[analyzer] Add a simple check for initializing reference variables with null.
There's still more work to be done here; this doesn't catch reference
parameters or return values. But it's a step in the right direction.
Part of <rdar://problem/11212286>.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@161214 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/test/Analysis/initializer.cpp b/test/Analysis/initializer.cpp
index 3f008ff..f7a6fd7 100644
--- a/test/Analysis/initializer.cpp
+++ b/test/Analysis/initializer.cpp
@@ -43,3 +43,24 @@
IndirectMember obj(3);
clang_analyzer_eval(obj.getX() == 3); // expected-warning{{TRUE}}
}
+
+
+// ------------------------------------
+// False negatives
+// ------------------------------------
+
+struct RefWrapper {
+ RefWrapper(int *p) : x(*p) {}
+ RefWrapper(int &r) : x(r) {}
+ int &x;
+};
+
+void testReferenceMember() {
+ int *p = 0;
+ RefWrapper X(p); // should warn in the constructor
+}
+
+void testReferenceMember2() {
+ int *p = 0;
+ RefWrapper X(*p); // should warn here
+}