summaryrefslogtreecommitdiffstats
path: root/test/SemaCXX/warn-undefined-bool-conversion.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'test/SemaCXX/warn-undefined-bool-conversion.cpp')
-rw-r--r--test/SemaCXX/warn-undefined-bool-conversion.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/test/SemaCXX/warn-undefined-bool-conversion.cpp b/test/SemaCXX/warn-undefined-bool-conversion.cpp
index 1f8baa0..24099f7 100644
--- a/test/SemaCXX/warn-undefined-bool-conversion.cpp
+++ b/test/SemaCXX/warn-undefined-bool-conversion.cpp
@@ -95,3 +95,27 @@ namespace function_return_reference {
// expected-warning@-1{{reference cannot be bound to dereferenced null pointer in well-defined C++ code; pointer may be assumed to always convert to true}}
}
}
+
+namespace macros {
+ #define assert(x) if (x) {}
+ #define zero_on_null(x) ((x) ? *(x) : 0)
+
+ void test(int &x) {
+ // TODO: warn on assert(&x) but not on zero_on_null(&x)
+ zero_on_null(&x);
+ assert(zero_on_null(&x));
+ assert(&x);
+
+ assert(&x && "Expecting valid reference");
+ // expected-warning@-1{{reference cannot be bound to dereferenced null pointer in well-defined C++ code; pointer may be assumed to always convert to true}}
+ }
+
+ class S {
+ void test() {
+ assert(this);
+
+ assert(this && "Expecting invalid reference");
+ // expected-warning@-1{{'this' pointer cannot be null in well-defined C++ code; pointer may be assumed to always convert to true}}
+ }
+ };
+}
OpenPOWER on IntegriCloud