Fortran: Fix PR 47485.
[gcc.git] / gcc / testsuite / g++.dg / warn / Wnvdtor-2.C
blob9f2e4bea43b51959a7d23b4fce8a8fbf600bed7c
1 // PR c++/7302
2 // { dg-do compile }
3 // { dg-options "-Wnon-virtual-dtor" }
5 // Warn when a class has virtual functions and accessible non-virtual
6 // destructor, in which case it would be possible but unsafe to delete
7 // an instance of a derived class through a pointer to the base class.
9 struct A
11 protected:
12   ~A(); // inaccessible - no warning
13 public:
14   virtual void f() = 0;
17 struct B
19 private:
20   ~B(); // inaccessible - no warning
21 public:
22   virtual void f() = 0;
25 struct C // { dg-warning "non-virtual destructor" }
27   virtual void f() = 0;
30 struct D // { dg-warning "non-virtual destructor" }
32   ~D();
33   virtual void f() = 0;
36 struct E;
38 struct F // { dg-warning "non-virtual destructor" }
40 protected:
41   friend class E;
42   ~F();
43 public:
44   virtual void f() = 0;
47 struct G // { dg-warning "non-virtual destructor" }
49 private:
50   friend class E;
51   ~G();
52 public:
53   virtual void f() = 0;
56 struct H {};
58 struct I1 : H
59 {};
60 struct I2 : private H
61 {};
63 struct J1 : H
64 { virtual ~J1 ();};
65 struct J2 : private H
66 { virtual ~J2 ();};
68 struct K // { dg-warning "accessible non-virtual destructor" }
70   virtual void k ();
73 struct L1 : K // { dg-warning "accessible non-virtual destructor" }
74 {virtual ~L1 ();};
75 struct L2 : private K
76 {virtual ~L2 ();};