method-call-path-notes.cpp revision 9da59a67a27a4d3fc9d59552f07808a32f85e9d3
1// RUN: %clang_cc1 -analyze -analyzer-checker=core -analyzer-ipa=inlining -analyzer-output=text -verify %s
2
3// Test warning about null or uninitialized pointer values used as instance member
4// calls.
5class TestInstanceCall {
6public:
7  void foo() {}
8};
9
10void test_ic() {
11  TestInstanceCall *p; // expected-note {{Variable 'p' declared without an initial value}}
12  p->foo(); // expected-warning {{Called C++ object pointer is uninitialized}} expected-note {{Called C++ object pointer is uninitialized}}
13}
14
15void test_ic_null() {
16  TestInstanceCall *p = 0; // expected-note {{Variable 'p' initialized to a null pointer value}}
17  p->foo(); // expected-warning {{Called C++ object pointer is null}} expected-note {{Called C++ object pointer is null}}
18}
19
20void test_ic_set_to_null() {
21  TestInstanceCall *p;
22  p = 0; // expected-note {{Null pointer value stored to 'p'}}
23  p->foo(); // expected-warning {{Called C++ object pointer is null}} expected-note {{Called C++ object pointer is null}}
24}
25
26void test_ic_null(TestInstanceCall *p) {
27  if (!p) // expected-note {{Taking true branch}}
28    p->foo(); // expected-warning {{Called C++ object pointer is null}} expected-note{{Called C++ object pointer is null}}
29}
30
31void test_ic_member_ptr() {
32  TestInstanceCall *p = 0; // expected-note {{Variable 'p' initialized to a null pointer value}}
33  typedef void (TestInstanceCall::*IC_Ptr)();
34  IC_Ptr bar = &TestInstanceCall::foo;
35  (p->*bar)(); // expected-warning {{Called C++ object pointer is null}} expected-note{{Called C++ object pointer is null}}
36}
37