1 // RUN: %clang_cc1 -analyze -analyzer-checker=core,cplusplus.NewDeleteLeaks -verify %s
2 
3 class A0 {};
4 
5 class A1 {
6 public:
7   A1(int);
8 };
9 
10 struct S{
11   int i;
12 };
13 
14 class A2 {
15 public:
16   A2();
17   A2(S);
18   A2(int*);
19   A2(S*);
20   A2(S&, int);
21   A2(int, S**);
22 };
23 
24 void test() {
25   new int; // expected-warning@+1 {{Potential memory leak}}
26   new A0; // expected-warning@+1 {{Potential memory leak}}
27   new A1(0); // expected-warning@+1 {{Potential memory leak}}
28   new A2; // expected-warning@+1 {{Potential memory leak}}
29   S s;
30   s.i = 1;
31   S* ps = new S;
32   new A2(s); // expected-warning@+1 {{Potential memory leak}}
33   new A2(&(s.i)); // expected-warning@+1 {{Potential memory leak}}
34   new A2(ps); // no warning
35   new A2(*ps, 1); // no warning
36   new A2(1, &ps); // no warning
37 
38   // Tests to ensure that leaks are reported for consumed news no matter what the arguments are.
39   A2 *a2p1 = new A2; // expected-warning@+1 {{Potential leak of memory}}
40   A2 *a2p2 = new A2(ps); // expected-warning@+1 {{Potential leak of memory}}
41   A2 *a2p3 = new A2(*ps, 1); // expected-warning@+1 {{Potential leak of memory}}
42   A2 *a2p4 = new A2(1, &ps); // expected-warning@+1 {{Potential leak of memory}}
43 }
44