55 lines · cpp
1// RUN: %clang_cc1 %s -fsyntax-only -verify -Wcall-to-pure-virtual-from-ctor-dtor2struct A {3 A() { f(); } // expected-warning {{call to pure virtual member function 'f' has undefined behavior; overrides of 'f' in subclasses are not available in the constructor of 'A'}}4 ~A() { f(); } // expected-warning {{call to pure virtual member function 'f' has undefined behavior; overrides of 'f' in subclasses are not available in the destructor of 'A'}}5 6 virtual void f() = 0; // expected-note 2 {{'f' declared here}}7};8 9// Don't warn (or note) when calling the function on a pointer. (PR10195)10struct B {11 A *a;12 B() { a->f(); };13 ~B() { a->f(); };14};15 16// Don't warn if the call is fully qualified. (PR23215)17struct C {18 virtual void f() = 0;19 C() {20 C::f();21 }22};23 24template <typename T> struct TA {25 TA() { f(); } // expected-warning {{call to pure virtual member function 'f' has undefined behavior; overrides of 'f' in subclasses are not available in the constructor of 'TA<float>'}}26 ~TA() { f(); } // expected-warning {{call to pure virtual member function 'f' has undefined behavior; overrides of 'f' in subclasses are not available in the destructor of 'TA<float>'}}27 28 virtual void f() = 0; // expected-note 2{{'f' declared here}}29};30 31template <> struct TA<int> {32 TA() { f(); }33 ~TA() { f(); }34 void f();35};36 37template <> struct TA<long> {38 TA() { f(); } // expected-warning {{call to pure virtual member function 'f' has undefined behavior; overrides of 'f' in subclasses are not available in the constructor of 'TA<long>'}}39 ~TA() { f(); } // expected-warning {{call to pure virtual member function 'f' has undefined behavior; overrides of 'f' in subclasses are not available in the destructor of 'TA<long>'}}40 virtual void f() = 0; // expected-note 2{{'f' declared here}}41};42 43struct TB : TA<float> { // expected-note {{in instantiation of member function 'TA<float>::TA' requested here}}44 void f() override; // expected-note@-1 {{in instantiation of member function 'TA<float>::~TA' requested here}}45};46TB tb;47 48struct TC : TA<int> {}; // ok49TC tc; // ok50 51struct TD : TA<long> {52 void f() override;53};54TD td;55