diff options
Diffstat (limited to 'test/SemaCXX/warn-zero-nullptr.cpp')
-rw-r--r-- | test/SemaCXX/warn-zero-nullptr.cpp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/test/SemaCXX/warn-zero-nullptr.cpp b/test/SemaCXX/warn-zero-nullptr.cpp new file mode 100644 index 000000000000..edd2a759b70f --- /dev/null +++ b/test/SemaCXX/warn-zero-nullptr.cpp @@ -0,0 +1,27 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s -Wzero-as-null-pointer-constant -std=c++11 + +struct S {}; + +int (S::*mp0) = nullptr; +void (*fp0)() = nullptr; +void* p0 = nullptr; + +int (S::*mp1) = 0; // expected-warning{{zero as null pointer constant}} +void (*fp1)() = 0; // expected-warning{{zero as null pointer constant}} +void* p1 = 0; // expected-warning{{zero as null pointer constant}} + +// NULL is an integer constant expression, so warn on it too: +void* p2 = __null; // expected-warning{{zero as null pointer constant}} +void (*fp2)() = __null; // expected-warning{{zero as null pointer constant}} +int (S::*mp2) = __null; // expected-warning{{zero as null pointer constant}} + +void f0(void* v = 0); // expected-warning{{zero as null pointer constant}} +void f1(void* v); + +void g() { + f1(0); // expected-warning{{zero as null pointer constant}} +} + +// Warn on these too. Matches gcc and arguably makes sense. +void* pp = (decltype(nullptr))0; // expected-warning{{zero as null pointer constant}} +void* pp2 = static_cast<decltype(nullptr)>(0); // expected-warning{{zero as null pointer constant}} |