summaryrefslogtreecommitdiff
path: root/test/SemaCXX/warn-undefined-bool-conversion.cpp
diff options
context:
space:
mode:
authorRichard Trieu <rtrieu@google.com>2014-06-28 23:25:37 +0000
committerRichard Trieu <rtrieu@google.com>2014-06-28 23:25:37 +0000
commit00fb59690f98ef46666c640db5f7cd79ea4f5178 (patch)
tree25364008dcef78c909306e660833012e127fd959 /test/SemaCXX/warn-undefined-bool-conversion.cpp
parent8a905545a533f4fd355c3b3768fb07f287ae1072 (diff)
downloadclang-00fb59690f98ef46666c640db5f7cd79ea4f5178.tar.gz
Extend -Wtautological-undefined-compare and -Wundefined-bool-conversion to
trigger on taking the address of a reference that is returned from a function call. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@211989 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/SemaCXX/warn-undefined-bool-conversion.cpp')
-rw-r--r--test/SemaCXX/warn-undefined-bool-conversion.cpp60
1 files changed, 60 insertions, 0 deletions
diff --git a/test/SemaCXX/warn-undefined-bool-conversion.cpp b/test/SemaCXX/warn-undefined-bool-conversion.cpp
index 40bbbd84a8..1f8baa0e8d 100644
--- a/test/SemaCXX/warn-undefined-bool-conversion.cpp
+++ b/test/SemaCXX/warn-undefined-bool-conversion.cpp
@@ -35,3 +35,63 @@ class test2 {
int &x;
int y;
};
+
+namespace function_return_reference {
+ int& get_int();
+ // expected-note@-1 3{{'get_int' returns a reference}}
+ class B {
+ public:
+ static int &stat();
+ // expected-note@-1 3{{'stat' returns a reference}}
+ int &get();
+ // expected-note@-1 6{{'get' returns a reference}}
+ };
+
+ void test() {
+ if (&get_int()) {}
+ // 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}}
+ if (&(get_int())) {}
+ // 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}}
+ if (!&get_int()) {}
+ // 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}}
+
+ if (&B::stat()) {}
+ // 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}}
+ if (&(B::stat())) {}
+ // 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}}
+ if (!&B::stat()) {}
+ // 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}}
+
+ B b;
+ if (&b.get()) {}
+ // 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}}
+ if (&(b.get())) {}
+ // 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}}
+ if (!&b.get()) {}
+ // 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}}
+
+ B* b_ptr = &b;
+ if (&b_ptr->get()) {}
+ // 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}}
+ if (&(b_ptr->get())) {}
+ // 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}}
+ if (!&b_ptr->get()) {}
+ // 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}}
+
+ int& (B::*m_ptr)() = &B::get;
+ if (&(b.*m_ptr)()) {}
+ // 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}}
+ if (&((b.*m_ptr)())) {}
+ // 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}}
+ if (!&(b.*m_ptr)()) {}
+ // 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}}
+
+ int& (*f_ptr)() = &get_int;
+ if (&(*f_ptr)()) {}
+ // 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}}
+ if (&((*f_ptr)())) {}
+ // 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}}
+ if (!&(*f_ptr)()) {}
+ // 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}}
+ }
+}