diff options
author | Ted Kremenek <kremenek@apple.com> | 2012-07-26 00:22:32 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2012-07-26 00:22:32 +0000 |
commit | faef9cb6941a3033dc731e1e37d89ec017c5939c (patch) | |
tree | a708fde3c505c4b562718c7865a2873f23865ad1 /clang/test/Analysis/misc-ps-cxx0x.cpp | |
parent | 4bfc35509405ff7db4de3003f863d4eeea13ea19 (diff) | |
download | bcm5719-llvm-faef9cb6941a3033dc731e1e37d89ec017c5939c.tar.gz bcm5719-llvm-faef9cb6941a3033dc731e1e37d89ec017c5939c.zip |
Add static analyzer check for calling a C++ instance method with a null/uninitialized pointer.
llvm-svn: 160767
Diffstat (limited to 'clang/test/Analysis/misc-ps-cxx0x.cpp')
-rw-r--r-- | clang/test/Analysis/misc-ps-cxx0x.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/clang/test/Analysis/misc-ps-cxx0x.cpp b/clang/test/Analysis/misc-ps-cxx0x.cpp index 7712bb8dc3b..e1c78ed0723 100644 --- a/clang/test/Analysis/misc-ps-cxx0x.cpp +++ b/clang/test/Analysis/misc-ps-cxx0x.cpp @@ -87,4 +87,25 @@ void rdar11817693::operator=(const rdar11817693& src) { operator=(dynamic_cast<const rdar11817693_BaseBase&>(src)); } +// Test warning about null or uninitialized pointer values used as instance member +// calls. +class TestInstanceCall { +public: + void foo() {} +}; + +void test_ic() { + TestInstanceCall *p; + p->foo(); // expected-warning {{Called C++ object pointer is uninitialized}} +} + +void test_ic_null() { + TestInstanceCall *p = 0; + p->foo(); // expected-warning {{Called C++ object pointer is null}} +} + +void test_ic_null(TestInstanceCall *p) { + if (!p) + p->foo(); // expected-warning {{Called C++ object pointer is null}} +} |