1 // RUN: %clang_cc1 -analyze -analyzer-checker=alpha.cplusplus.VirtualCall -analyzer-store region -verify %s 2 3 class A { 4 public: 5 A(); 6 ~A() {}; 7 8 virtual int foo() = 0; 9 virtual void bar() = 0; 10 void f() { 11 foo(); // expected-warning{{Call pure virtual functions during construction or destruction may leads undefined behaviour}} 12 } 13 }; 14 15 class B : public A { 16 public: 17 B() { 18 foo(); // expected-warning{{Call virtual functions during construction or destruction will never go to a more derived class}} 19 } 20 ~B(); 21 22 virtual int foo(); 23 virtual void bar() { foo(); } // expected-warning{{Call virtual functions during construction or destruction will never go to a more derived class}} 24 }; 25 26 A::A() { 27 f(); 28 } 29 30 B::~B() { 31 this->B::foo(); // no-warning 32 this->B::bar(); 33 this->foo(); // expected-warning{{Call virtual functions during construction or destruction will never go to a more derived class}} 34 } 35 36 class C : public B { 37 public: 38 C(); 39 ~C(); 40 41 virtual int foo(); 42 void f(int i); 43 }; 44 45 C::C() { 46 f(foo()); // expected-warning{{Call virtual functions during construction or destruction will never go to a more derived class}} 47 } 48 49 int main() { 50 A *a; 51 B *b; 52 C *c; 53 } 54 55 #include "virtualcall.h" 56 57 #define AS_SYSTEM 58 #include "virtualcall.h" 59 #undef AS_SYSTEM 60