aboutsummaryrefslogtreecommitdiffstats
path: root/gcc-4.9/gcc/testsuite/g++.dg/warn/Wnvdtor-3.C
blob: e83134b062bf83a44b3e057b8207359b7a15f3d7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// { dg-do compile }
// { dg-options "-Weffc++" }

// Warn when a class has virtual functions and accessible non-virtual
// destructor, in which case it would be possible but unsafe to delete
// an instance of a derived class through a pointer to the base class.

struct A
{
protected:
  ~A(); // inaccessible - no warning
public:
  virtual void f() = 0;
};

struct B
{
private:
  ~B(); // inaccessible - no warning
public:
  virtual void f() = 0;
};

struct C // { dg-warning "non-virtual destructor" }
{
  virtual void f() = 0;
};

struct D // { dg-warning "non-virtual destructor" }
{
  ~D();
  virtual void f() = 0;
};

struct E;

struct F // { dg-warning "non-virtual destructor" }
{
protected:
  friend class E;
  ~F();
public:
  virtual void f() = 0;
};

struct G // { dg-warning "non-virtual destructor" }
{
private:
  friend class E;
  ~G();
public:
  virtual void f() = 0;
};

struct H {};

struct I1 : H
{};
struct I2 : private H
{};

struct J1 : H // { dg-warning "accessible non-virtual destructor" }
{ virtual ~J1 ();};
struct J2 : private H
{ virtual ~J2 ();};

struct K // { dg-warning "accessible non-virtual destructor" }
{
  virtual void k ();
};

struct L1 : K // { dg-warning "accessible non-virtual destructor" }
{virtual ~L1 ();};
struct L2 : private K
{virtual ~L2 ();};