blob: c3319b0ac54fc08c17309cdb0aa817e915989987 [file] [log] [blame]
Ted Kremenekcdc3a892012-08-24 20:39:55 +00001// RUN: %clang_cc1 -analyze -analyzer-checker=alpha.cplusplus.VirtualCall -analyzer-store region -verify %s
Ted Kremenekde9f2532012-01-03 23:18:57 +00002
3class A {
4public:
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
15class B : public A {
16public:
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
26A::A() {
27 f();
28}
29
30B::~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
36class C : public B {
37public:
38 C();
39 ~C();
40
41 virtual int foo();
42 void f(int i);
43};
44
45C::C() {
46 f(foo()); // expected-warning{{Call virtual functions during construction or destruction will never go to a more derived class}}
47}
48
49int main() {
50 A *a;
51 B *b;
52 C *c;
53}
Jordan Rose4eff6b52012-10-10 17:55:40 +000054
55#include "virtualcall.h"
56
57#define AS_SYSTEM
58#include "virtualcall.h"
59#undef AS_SYSTEM