diff options
Diffstat (limited to 'test/Analysis/virtualcall.cpp')
-rw-r--r-- | test/Analysis/virtualcall.cpp | 64 |
1 files changed, 57 insertions, 7 deletions
diff --git a/test/Analysis/virtualcall.cpp b/test/Analysis/virtualcall.cpp index 8ce1d4103b9c..e42b898a0738 100644 --- a/test/Analysis/virtualcall.cpp +++ b/test/Analysis/virtualcall.cpp @@ -1,36 +1,79 @@ -// RUN: %clang_cc1 -analyze -analyzer-checker=alpha.cplusplus.VirtualCall -analyzer-store region -verify -std=c++11 %s +// RUN: %clang_cc1 -analyze -analyzer-checker=optin.cplusplus.VirtualCall -analyzer-store region -verify -std=c++11 %s +// RUN: %clang_cc1 -analyze -analyzer-checker=optin.cplusplus.VirtualCall -analyzer-store region -analyzer-config optin.cplusplus.VirtualCall:Interprocedural=true -DINTERPROCEDURAL=1 -verify -std=c++11 %s +// RUN: %clang_cc1 -analyze -analyzer-checker=optin.cplusplus.VirtualCall -analyzer-store region -analyzer-config optin.cplusplus.VirtualCall:PureOnly=true -DPUREONLY=1 -verify -std=c++11 %s + +/* When INTERPROCEDURAL is set, we expect diagnostics in all functions reachable + from a constructor or destructor. If it is not set, we expect diagnostics + only in the constructor or destructor. + + When PUREONLY is set, we expect diagnostics only for calls to pure virtual + functions not to non-pure virtual functions. +*/ class A { public: A(); + A(int i); + ~A() {}; - virtual int foo() = 0; + virtual int foo() = 0; // from Sema: expected-note {{'foo' declared here}} virtual void bar() = 0; void f() { - foo(); // expected-warning{{Call pure virtual functions during construction or destruction may leads undefined behaviour}} + foo(); +#if INTERPROCEDURAL + // expected-warning-re@-2 {{{{^}}Call Path : foo <-- fCall to pure virtual function during construction has undefined behavior}} +#endif } }; class B : public A { public: B() { - foo(); // expected-warning{{Call virtual functions during construction or destruction will never go to a more derived class}} + foo(); +#if !PUREONLY +#if INTERPROCEDURAL + // expected-warning-re@-3 {{{{^}}Call Path : fooCall to virtual function during construction will not dispatch to derived class}} +#else + // expected-warning-re@-5 {{{{^}}Call to virtual function during construction will not dispatch to derived class}} +#endif +#endif + } ~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}} + virtual void bar() { foo(); } +#if INTERPROCEDURAL + // expected-warning-re@-2 {{{{^}}Call Path : foo <-- barCall to virtual function during destruction will not dispatch to derived class}} +#endif }; A::A() { f(); } +A::A(int i) { + foo(); // From Sema: expected-warning {{call to pure virtual member function 'foo' has undefined behavior}} +#if INTERPROCEDURAL + // expected-warning-re@-2 {{{{^}}Call Path : fooCall to pure virtual function during construction has undefined behavior}} +#else + // expected-warning-re@-4 {{{{^}}Call to pure virtual function during construction has undefined behavior}} +#endif +} + 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}} + this->foo(); +#if !PUREONLY +#if INTERPROCEDURAL + // expected-warning-re@-3 {{{{^}}Call Path : fooCall to virtual function during destruction will not dispatch to derived class}} +#else + // expected-warning-re@-5 {{{{^}}Call to virtual function during destruction will not dispatch to derived class}} +#endif +#endif + } class C : public B { @@ -43,7 +86,14 @@ public: }; C::C() { - f(foo()); // expected-warning{{Call virtual functions during construction or destruction will never go to a more derived class}} + f(foo()); +#if !PUREONLY +#if INTERPROCEDURAL + // expected-warning-re@-3 {{{{^}}Call Path : fooCall to virtual function during construction will not dispatch to derived class}} +#else + // expected-warning-re@-5 {{{{^}}Call to virtual function during construction will not dispatch to derived class}} +#endif +#endif } class D : public B { |