42 lines · cpp
1// RUN: %clang_analyze_cc1 -std=c++14 \2// RUN: -analyzer-checker=core,debug.ExprInspection \3// RUN: -verify %s4 5void clang_analyzer_eval(bool);6void clang_analyzer_warnIfReached();7 8typedef __typeof__(sizeof(int)) size_t;9 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}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 19struct S {20 int x;21 S() : x(1) {22 // FIXME: Constructor should not be called with null this, even if it was23 // returned by operator new().24 clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}25 }26 ~S() {}27};28 29void testArrays() {30 S *s = new S[10]; // no-crash31 s[0].x = 2;32 // no-warning: 'Dereference of null pointer' suppressed by ReturnVisitor.33}34 35int global;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