1 // RUN: %clang_analyze_cc1 -analyzer-checker=core -analyzer-output=text -verify %s
2 // RUN: %clang_analyze_cc1 -analyzer-checker=core -analyzer-output=plist-multi-file %s -o %t.plist
3 // RUN: %normalize_plist <%t.plist | diff -ub %S/Inputs/expected-plists/method-call-path-notes.cpp.plist -
5 // Test warning about null or uninitialized pointer values used as instance member
7 class TestInstanceCall
{
13 TestInstanceCall
*p
; // expected-note {{'p' declared without an initial value}}
14 p
->foo(); // expected-warning {{Called C++ object pointer is uninitialized}} expected-note {{Called C++ object pointer is uninitialized}}
18 TestInstanceCall
*p
= 0; // expected-note {{'p' initialized to a null pointer value}}
19 p
->foo(); // expected-warning {{Called C++ object pointer is null}} expected-note {{Called C++ object pointer is null}}
22 void test_ic_set_to_null() {
24 p
= 0; // expected-note {{Null pointer value stored to 'p'}}
25 p
->foo(); // expected-warning {{Called C++ object pointer is null}} expected-note {{Called C++ object pointer is null}}
28 void test_ic_null(TestInstanceCall
*p
) {
29 if (!p
) // expected-note {{Assuming 'p' is null}} expected-note {{Taking true branch}}
30 p
->foo(); // expected-warning {{Called C++ object pointer is null}} expected-note{{Called C++ object pointer is null}}
33 void test_ic_member_ptr() {
34 TestInstanceCall
*p
= 0; // expected-note {{'p' initialized to a null pointer value}}
35 typedef void (TestInstanceCall::*IC_Ptr
)();
36 IC_Ptr bar
= &TestInstanceCall::foo
;
37 (p
->*bar
)(); // expected-warning {{Called C++ object pointer is null}} expected-note{{Called C++ object pointer is null}}
40 void test_cast(const TestInstanceCall
*p
) {
41 if (!p
) // expected-note {{Assuming 'p' is null}} expected-note {{Taking true branch}}
42 const_cast<TestInstanceCall
*>(p
)->foo(); // expected-warning {{Called C++ object pointer is null}} expected-note {{Called C++ object pointer is null}}