1 // { dg-do compile }
2 // { dg-options "-Weffc++" }
3 
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.
7 
8 struct A
9 {
10 protected:
11   ~A(); // inaccessible - no warning
12 public:
13   virtual void f() = 0;
14 };
15 
16 struct B
17 {
18 private:
19   ~B(); // inaccessible - no warning
20 public:
21   virtual void f() = 0;
22 };
23 
24 struct C // { dg-warning "non-virtual destructor" }
25 {
26   virtual void f() = 0;
27 };
28 
29 struct D // { dg-warning "non-virtual destructor" }
30 {
31   ~D();
32   virtual void f() = 0;
33 };
34 
35 struct E;
36 
37 struct F // { dg-warning "non-virtual destructor" }
38 {
39 protected:
40   friend class E;
41   ~F();
42 public:
43   virtual void f() = 0;
44 };
45 
46 struct G // { dg-warning "non-virtual destructor" }
47 {
48 private:
49   friend class E;
50   ~G();
51 public:
52   virtual void f() = 0;
53 };
54 
55 struct H {};
56 
57 struct I1 : H
58 {};
59 struct I2 : private H
60 {};
61 
62 struct J1 : H // { dg-warning "accessible non-virtual destructor" }
63 { virtual ~J1 ();};
64 struct J2 : private H
65 { virtual ~J2 ();};
66 
67 struct K // { dg-warning "accessible non-virtual destructor" }
68 {
69   virtual void k ();
70 };
71 
72 struct L1 : K // { dg-warning "accessible non-virtual destructor" }
73 {virtual ~L1 ();};
74 struct L2 : private K
75 {virtual ~L2 ();};
76