summaryrefslogtreecommitdiff
path: root/test/SemaCXX/warn-tautological-undefined-compare.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'test/SemaCXX/warn-tautological-undefined-compare.cpp')
-rw-r--r--test/SemaCXX/warn-tautological-undefined-compare.cpp28
1 files changed, 28 insertions, 0 deletions
diff --git a/test/SemaCXX/warn-tautological-undefined-compare.cpp b/test/SemaCXX/warn-tautological-undefined-compare.cpp
index ce05bfc14d170..9321c0edbd3a2 100644
--- a/test/SemaCXX/warn-tautological-undefined-compare.cpp
+++ b/test/SemaCXX/warn-tautological-undefined-compare.cpp
@@ -110,3 +110,31 @@ namespace function_return_reference {
// expected-warning@-1{{reference cannot be bound to dereferenced null pointer in well-defined C++ code; comparison may be assumed to always evaluate to true}}
}
}
+
+namespace macros {
+ #define assert(x) if (x) {}
+
+ void test(int &x) {
+ assert(&x != 0);
+ // expected-warning@-1{{reference cannot be bound to dereferenced null pointer in well-defined C++ code; comparison may be assumed to always evaluate to true}}
+ assert(&x == 0);
+ // expected-warning@-1{{reference cannot be bound to dereferenced null pointer in well-defined C++ code; comparison may be assumed to always evaluate to false}}
+ assert(&x != 0 && "Expecting valid reference");
+ // expected-warning@-1{{reference cannot be bound to dereferenced null pointer in well-defined C++ code; comparison may be assumed to always evaluate to true}}
+ assert(&x == 0 && "Expecting invalid reference");
+ // expected-warning@-1{{reference cannot be bound to dereferenced null pointer in well-defined C++ code; comparison may be assumed to always evaluate to false}}
+ }
+
+ class S {
+ void test() {
+ assert(this != 0);
+ // expected-warning@-1{{'this' pointer cannot be null in well-defined C++ code; comparison may be assumed to always evaluate to true}}
+ assert(this == 0);
+ // expected-warning@-1{{'this' pointer cannot be null in well-defined C++ code; comparison may be assumed to always evaluate to false}}
+ assert(this != 0 && "Expecting valid reference");
+ // expected-warning@-1{{'this' pointer cannot be null in well-defined C++ code; comparison may be assumed to always evaluate to true}}
+ assert(this == 0 && "Expecting invalid reference");
+ // expected-warning@-1{{'this' pointer cannot be null in well-defined C++ code; comparison may be assumed to always evaluate to false}}
+ }
+ };
+}