PR middle-end/77674
[official-gcc.git] / gcc / testsuite / g++.dg / warn / Wnvdtor-3.C
blobe83134b062bf83a44b3e057b8207359b7a15f3d7
1 // { dg-do compile }
2 // { dg-options "-Weffc++" }
4 // Warn when a class has virtual functions and accessible non-virtual
5 // destructor, in which case it would be possible but unsafe to delete
6 // an instance of a derived class through a pointer to the base class.
8 struct A
10 protected:
11   ~A(); // inaccessible - no warning
12 public:
13   virtual void f() = 0;
16 struct B
18 private:
19   ~B(); // inaccessible - no warning
20 public:
21   virtual void f() = 0;
24 struct C // { dg-warning "non-virtual destructor" }
26   virtual void f() = 0;
29 struct D // { dg-warning "non-virtual destructor" }
31   ~D();
32   virtual void f() = 0;
35 struct E;
37 struct F // { dg-warning "non-virtual destructor" }
39 protected:
40   friend class E;
41   ~F();
42 public:
43   virtual void f() = 0;
46 struct G // { dg-warning "non-virtual destructor" }
48 private:
49   friend class E;
50   ~G();
51 public:
52   virtual void f() = 0;
55 struct H {};
57 struct I1 : H
58 {};
59 struct I2 : private H
60 {};
62 struct J1 : H // { dg-warning "accessible non-virtual destructor" }
63 { virtual ~J1 ();};
64 struct J2 : private H
65 { virtual ~J2 ();};
67 struct K // { dg-warning "accessible non-virtual destructor" }
69   virtual void k ();
72 struct L1 : K // { dg-warning "accessible non-virtual destructor" }
73 {virtual ~L1 ();};
74 struct L2 : private K
75 {virtual ~L2 ();};