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