blob: 8ce1d4103b9c15171c7ea64c5e30024ac0989d41 [file] [log] [blame]
Stephen Hines176edba2014-12-01 14:53:08 -08001// RUN: %clang_cc1 -analyze -analyzer-checker=alpha.cplusplus.VirtualCall -analyzer-store region -verify -std=c++11 %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
Stephen Hines176edba2014-12-01 14:53:08 -080049class D : public B {
50public:
51 D() {
52 foo(); // no-warning
53 }
54 ~D() { bar(); }
55 int foo() final;
56 void bar() final { foo(); } // no-warning
57};
58
59class E final : public B {
60public:
61 E() {
62 foo(); // no-warning
63 }
64 ~E() { bar(); }
65 int foo() override;
66};
67
Ted Kremenekde9f2532012-01-03 23:18:57 +000068int main() {
69 A *a;
70 B *b;
71 C *c;
Stephen Hines176edba2014-12-01 14:53:08 -080072 D *d;
73 E *e;
Ted Kremenekde9f2532012-01-03 23:18:57 +000074}
Jordan Rose4eff6b52012-10-10 17:55:40 +000075
76#include "virtualcall.h"
77
78#define AS_SYSTEM
79#include "virtualcall.h"
80#undef AS_SYSTEM