1 // RUN: %clang_analyze_cc1 -analyzer-checker=core,optin.cplusplus.VirtualCall \
2 // RUN: -analyzer-checker=debug.ExprInspection \
3 // RUN: -std=c++11 -verify=impure %s
5 // RUN: %clang_analyze_cc1 -analyzer-checker=core,cplusplus.PureVirtualCall \
6 // RUN: -analyzer-checker=debug.ExprInspection \
7 // RUN: -std=c++11 -verify=pure -std=c++11 %s
9 // RUN: %clang_analyze_cc1 -analyzer-checker=core,optin.cplusplus.VirtualCall \
10 // RUN: -analyzer-config \
11 // RUN: optin.cplusplus.VirtualCall:PureOnly=true \
12 // RUN: -analyzer-checker=debug.ExprInspection \
13 // RUN: -std=c++11 -verify=none %s
15 // RUN: %clang_analyze_cc1 -analyzer-checker=core,cplusplus.PureVirtualCall \
16 // RUN: -analyzer-checker=optin.cplusplus.VirtualCall \
17 // RUN: -analyzer-checker=debug.ExprInspection \
18 // RUN: -std=c++11 -verify=pure,impure -std=c++11 %s
20 // RUN: %clang_analyze_cc1 -analyzer-checker=core,cplusplus.PureVirtualCall \
21 // RUN: -analyzer-checker=optin.cplusplus.VirtualCall \
22 // RUN: -analyzer-config \
23 // RUN: optin.cplusplus.VirtualCall:PureOnly=true \
24 // RUN: -analyzer-checker=debug.ExprInspection \
25 // RUN: -std=c++11 -verify=pure %s
28 // We expect no diagnostics when all checks are disabled.
29 // none-no-diagnostics
32 #include "virtualcall.h"
34 void clang_analyzer_warnIfReached();
42 virtual int foo() = 0;
43 virtual void bar() = 0;
45 foo(); // pure-warning{{Call to pure virtual method 'A::foo' during construction has undefined behavior}}
46 clang_analyzer_warnIfReached(); // no-warning
57 foo(); // impure-warning {{Call to virtual method 'B::foo' during construction bypasses virtual dispatch}}
63 foo(); // impure-warning {{Call to virtual method 'B::foo' during destruction bypasses virtual dispatch}}
68 this->B::foo(); // no-warning
70 this->foo(); // impure-warning {{Call to virtual method 'B::foo' during destruction bypasses virtual dispatch}}
83 f(foo()); // impure-warning {{Call to virtual method 'C::foo' during construction bypasses virtual dispatch}}
93 void bar() final
{ foo(); } // no-warning
96 class E final
: public B
{
108 void (F::*ptr
)() = &F::foo
;
125 H() : initState(0) { init(); }
127 virtual void f() const;
136 g
.bar(); // no warning
137 f(); // impure-warning {{Call to virtual method 'H::f' during construction bypasses virtual dispatch}}
139 h
.f(); // impure-warning {{Call to virtual method 'H::f' during construction bypasses virtual dispatch}}
146 g(); // impure-warning {{Call to virtual method 'X::g' during construction bypasses virtual dispatch}}
153 g(); // impure-warning {{Call to virtual method 'X::g' during construction bypasses virtual dispatch}}
161 virtual void virtualMethod();
162 void callFooOfM(M
*);
168 n
.virtualMethod(); // no warning
173 void N::callFooOfM(M
*m
) {
174 m
->foo(); // impure-warning {{Call to virtual method 'M::foo' during construction bypasses virtual dispatch}}
179 virtual void foobar();
182 foobar(); // impure-warning {{Call to virtual method 'Y::foobar' during construction bypasses virtual dispatch}}
222 void c::m_fn2() const { d
->b(); }