diff options
Diffstat (limited to 'clang/test/SemaCXX/warn-undefined-bool-conversion.cpp')
-rw-r--r-- | clang/test/SemaCXX/warn-undefined-bool-conversion.cpp | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/clang/test/SemaCXX/warn-undefined-bool-conversion.cpp b/clang/test/SemaCXX/warn-undefined-bool-conversion.cpp new file mode 100644 index 00000000000..c56b6bc1595 --- /dev/null +++ b/clang/test/SemaCXX/warn-undefined-bool-conversion.cpp @@ -0,0 +1,37 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wundefined-bool-conversion %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wno-bool-conversion -Wundefined-bool-conversion %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wbool-conversion %s + +void test1(int &x) { + if (x == 1) { } + if (&x) { } + // expected-warning@-1{{reference cannot be bound to dereferenced null pointer in well-defined C++ code; pointer may be assumed always converted to true}} + + if (!&x) { } + // expected-warning@-1{{reference cannot be bound to dereferenced null pointer in well-defined C++ code; pointer may be assumed always converted to true}} +} + +class test2 { + test2() : x(y) {} + + void foo() { + if (this) { } + // expected-warning@-1{{'this' pointer cannot be null in well-defined C++ code; pointer may be assumed always converted to true}} + + if (!this) { } + // expected-warning@-1{{'this' pointer cannot be null in well-defined C++ code; pointer may be assumed always converted to true}} + } + + void bar() { + if (x == 1) { } + if (&x) { } + // expected-warning@-1{{reference cannot be bound to dereferenced null pointer in well-defined C++ code; pointer may be assumed always converted to true}} + + if (!&x) { } + // expected-warning@-1{{reference cannot be bound to dereferenced null pointer in well-defined C++ code; pointer may be assumed always converted to true}} + } + + int &x; + int y; +}; |