blob: 9849b1edfa8e662238685c6cc51b9a635d9705f8 (
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
|
// { dg-options "-std=gnu++0x -Wdelete-non-virtual-dtor" }
// { dg-do compile }
struct polyBase { virtual void f(); };
void f(polyBase* p, polyBase* arr)
{
delete p; // { dg-warning "non-virtual destructor might" }
delete [] arr;
}
struct polyDerived : polyBase { };
void f(polyDerived* p, polyDerived* arr)
{
delete p; // { dg-warning "non-virtual destructor might" }
delete [] arr;
}
struct absDerived : polyBase { virtual void g() = 0; };
void f(absDerived* p, absDerived* arr)
{
delete p; // { dg-warning "non-virtual destructor will" }
delete [] arr;
}
struct finalDerived final : polyBase { };
void f(finalDerived* p, finalDerived* arr)
{
delete p; // no error for final classes
delete [] arr;
}
struct safeBase { virtual ~safeBase(); };
struct safeDerived : safeBase { virtual void f(); };
void f(safeDerived* p, safeDerived* arr)
{
delete p; // no error because base has virtual dtor
delete [] arr;
}
|