56 lines · cpp
1// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -analyzer-config c++-allocator-inlining=true -std=c++11 -verify -analyzer-config eagerly-assume=false %s2 3void clang_analyzer_eval(bool);4 5typedef __typeof__(sizeof(int)) size_t;6 7void *conjure();8void exit(int);9 10void *operator new(size_t size) throw() {11 void *x = conjure();12 if (x == 0)13 exit(1);14 return x;15}16 17struct S {18 int x;19 S() : x(1) {}20 ~S() {}21};22 23void checkNewAndConstructorInlining() {24 S *s = new S;25 // Check that the symbol for 's' is not dying.26 clang_analyzer_eval(s != 0); // expected-warning{{TRUE}}27 // Check that bindings are correct (and also not dying).28 clang_analyzer_eval(s->x == 1); // expected-warning{{TRUE}}29}30 31struct Sp {32 Sp *p;33 Sp(Sp *p): p(p) {}34 ~Sp() {}35};36 37void checkNestedNew() {38 Sp *p = new Sp(new Sp(0));39 clang_analyzer_eval(p->p->p == 0); // expected-warning{{TRUE}}40}41 42void checkNewPOD() {43 int *i = new int;44 clang_analyzer_eval(*i == 0); // expected-warning{{UNKNOWN}}45 int *j = new int();46 clang_analyzer_eval(*j == 0); // expected-warning{{TRUE}}47 int *k = new int(5);48 clang_analyzer_eval(*k == 5); // expected-warning{{TRUE}}49}50 51void checkTrivialCopy() {52 S s;53 S *t = new S(s); // no-crash54 clang_analyzer_eval(t->x == 1); // expected-warning{{TRUE}}55}56