1 // RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -analyzer-config c++-allocator-inlining=true -std=c++11 -verify %s
2 
3 void clang_analyzer_eval(bool);
4 void clang_analyzer_warnIfReached();
5 
6 typedef __typeof__(sizeof(int)) size_t;
7 
8 void *operator new(size_t size) throw() {
9   return nullptr;
10 }
11 void *operator new[](size_t size) throw() {
12   return nullptr;
13 }
14 
15 struct S {
16   int x;
17   S() : x(1) {
18     // FIXME: Constructor should not be called with null this, even if it was
19     // returned by operator new().
20     clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
21   }
22   ~S() {}
23 };
24 
25 void testArrays() {
26   S *s = new S[10]; // no-crash
27   s[0].x = 2; // expected-warning{{Dereference of null pointer}}
28 }
29 
30 int global;
31 void testInvalidationOnConstructionIntoNull() {
32   global = 0;
33   S *s = new S();
34   // FIXME: Should be FALSE - we should not invalidate globals.
35   clang_analyzer_eval(global); // expected-warning{{UNKNOWN}}
36 }
37