1 // RUN: %clang_analyze_cc1 -w -analyzer-checker=core,debug.ExprInspection -analyzer-config c++-allocator-inlining=true -std=c++11 -verify -analyzer-config eagerly-assume=false %s
2 
3 void clang_analyzer_eval(bool);
4 void clang_analyzer_warnIfReached();
5 
6 struct S {
7   int x;
SS8   S() : x(1) {}
~SS9   ~S() {}
10 };
11 
checkConstructorInlining()12 void checkConstructorInlining() {
13   S *s = new S;
14   clang_analyzer_eval(s->x == 1); // expected-warning{{TRUE}}
15 }
16 
checkNewPOD()17 void checkNewPOD() {
18   int *i = new int;
19   clang_analyzer_eval(*i == 0); // expected-warning{{UNKNOWN}}
20   int *j = new int();
21   clang_analyzer_eval(*j == 0); // expected-warning{{TRUE}}
22   int *k = new int(5);
23   clang_analyzer_eval(*k == 5); // expected-warning{{TRUE}}
24 }
25 
checkNewArray()26 void checkNewArray() {
27   S *s = new S[10];
28   // FIXME: Should be true once we inline array constructors.
29   clang_analyzer_eval(s[0].x == 1); // expected-warning{{UNKNOWN}}
30   clang_analyzer_eval(s[1].x == 1); // expected-warning{{UNKNOWN}}
31 }
32 
33 struct NullS {
NullSNullS34   NullS() {
35     if (this) {}
36   }
NullSNullS37   NullS(int x) {
38     if (!this) {
39       clang_analyzer_warnIfReached(); // no-warning
40     }
41   }
42 };
43 
checkNullThis()44 void checkNullThis() {
45   NullS *nulls = new NullS(); // no-crash
46   NullS *nulls2 = new NullS(0);
47 }
48