[clang] Handle __declspec() attributes in using
[llvm-project.git] / clang / test / SemaCXX / warn-pure-virtual-call-from-ctor-dtor.cpp
blob9acf84c6ce8c5e41655760a703401548928dade1
1 // RUN: %clang_cc1 %s -fsyntax-only -verify -Wcall-to-pure-virtual-from-ctor-dtor
2 struct 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'}}
6 virtual void f() = 0; // expected-note 2 {{'f' declared here}}
7 };
9 // Don't warn (or note) when calling the function on a pointer. (PR10195)
10 struct B {
11 A *a;
12 B() { a->f(); };
13 ~B() { a->f(); };
16 // Don't warn if the call is fully qualified. (PR23215)
17 struct C {
18 virtual void f() = 0;
19 C() {
20 C::f();
24 template <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>'}}
28 virtual void f() = 0; // expected-note 2{{'f' declared here}}
31 template <> struct TA<int> {
32 TA() { f(); }
33 ~TA() { f(); }
34 void f();
37 template <> 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}}
43 struct 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}}
46 TB tb;
48 struct TC : TA<int> {}; // ok
49 TC tc; // ok
51 struct TD : TA<long> {
52 void f() override;
54 TD td;