diff options
author | dim <dim@FreeBSD.org> | 2012-04-14 14:01:31 +0000 |
---|---|---|
committer | dim <dim@FreeBSD.org> | 2012-04-14 14:01:31 +0000 |
commit | 50b73317314e889cf39c7b1d6cbf419fa7502f22 (patch) | |
tree | be1815eb79b42ff482a8562b13c2dcbf0c5dcbee /test/Analysis/virtualcall.cpp | |
parent | dc04cb328508e61aad809d9b53b12f9799a00e7d (diff) | |
download | FreeBSD-src-50b73317314e889cf39c7b1d6cbf419fa7502f22.zip FreeBSD-src-50b73317314e889cf39c7b1d6cbf419fa7502f22.tar.gz |
Vendor import of clang trunk r154661:
http://llvm.org/svn/llvm-project/cfe/trunk@r154661
Diffstat (limited to 'test/Analysis/virtualcall.cpp')
-rw-r--r-- | test/Analysis/virtualcall.cpp | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/test/Analysis/virtualcall.cpp b/test/Analysis/virtualcall.cpp new file mode 100644 index 0000000..127d04f --- /dev/null +++ b/test/Analysis/virtualcall.cpp @@ -0,0 +1,53 @@ +// RUN: %clang_cc1 -analyze -analyzer-checker=experimental.cplusplus.VirtualCall -analyzer-store region -verify %s + +class A { +public: + A(); + ~A() {}; + + virtual int foo() = 0; + virtual void bar() = 0; + void f() { + foo(); // expected-warning{{Call pure virtual functions during construction or destruction may leads undefined behaviour}} + } +}; + +class B : public A { +public: + B() { + foo(); // expected-warning{{Call virtual functions during construction or destruction will never go to a more derived class}} + } + ~B(); + + virtual int foo(); + virtual void bar() { foo(); } // expected-warning{{Call virtual functions during construction or destruction will never go to a more derived class}} +}; + +A::A() { + f(); +} + +B::~B() { + this->B::foo(); // no-warning + this->B::bar(); + this->foo(); // expected-warning{{Call virtual functions during construction or destruction will never go to a more derived class}} +} + +class C : public B { +public: + C(); + ~C(); + + virtual int foo(); + void f(int i); +}; + +C::C() { + f(foo()); // expected-warning{{Call virtual functions during construction or destruction will never go to a more derived class}} +} + +int main() { + A *a; + B *b; + C *c; +} |