1 // RUN: %clang_cc1 -std=c++11 -Wno-conversion-null -analyze -analyzer-checker=core -analyzer-store region -verify %s
3 // test to see if nullptr is detected as a null pointer
6 *np = 0; // expected-warning{{Dereference of null pointer}}
9 // check if comparing nullptr to nullptr is detected properly
16 *np1 = 0; // no-warning
19 // invoving a nullptr in a more complex operation should be cause a warning
25 // casting a nullptr to anything should be caught eventually
26 int *ip = &(((struct foo *)np)->f);
27 *ip = 0; // expected-warning{{Dereference of null pointer}}
28 // should be error here too, but analysis gets stopped
32 // nullptr is implemented as a zero integer value, so should be able to compare
36 *np = 0; // no-warning
39 *np = 0; // no-warning
42 int pr10372(void *& x) {
43 // GNU null is a pointer-sized integer, not a pointer.
45 // This used to crash.
51 delete *(p + 0); // expected-warning{{Dereference of null pointer}}
59 :"0"(*b) // expected-warning{{Dereference of null pointer}}
63 int exprWithCleanups() {
72 return S(*x).a; // expected-warning{{Dereference of null pointer}}
75 int materializeTempExpr() {
81 const S &s = S(*n); // expected-warning{{Dereference of null pointer}}
85 typedef decltype(nullptr) nullptr_t;
86 void testMaterializeTemporaryExprWithNullPtr() {
87 // Create MaterializeTemporaryExpr with a nullptr inside.
88 const nullptr_t &r = nullptr;