diff options
author | Jordan Rose <jordan_rose@apple.com> | 2012-08-02 21:33:42 +0000 |
---|---|---|
committer | Jordan Rose <jordan_rose@apple.com> | 2012-08-02 21:33:42 +0000 |
commit | 9f3b9d54ccbbf212591602f389ebde7923627490 (patch) | |
tree | bcbcdb69c5cc0b5c12f7e4d52cf4cce11b7485d0 /test/Analysis/initializer.cpp | |
parent | c27bc80a98b9558513b50956c930eedc9e461ae0 (diff) |
[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
Diffstat (limited to 'test/Analysis/initializer.cpp')
-rw-r--r-- | test/Analysis/initializer.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/test/Analysis/initializer.cpp b/test/Analysis/initializer.cpp index 3f008ffbbf..f7a6fd7bea 100644 --- a/test/Analysis/initializer.cpp +++ b/test/Analysis/initializer.cpp @@ -43,3 +43,24 @@ void testIndirectMember() { 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 +} |