| 1 |
// PR ipa/83054 |
| 2 |
// { dg-options "-O3 -Wsuggest-final-types" } |
| 3 |
// { dg-do compile } |
| 4 |
|
| 5 |
// A throwing dtor in C++98 mode changes the warning. |
| 6 |
#if __cplusplus < 201100L |
| 7 |
#define NOTHROW throw() |
| 8 |
#else |
| 9 |
#define NOTHROW noexcept |
| 10 |
#endif |
| 11 |
|
| 12 |
extern "C" int printf (const char *, ...); |
| 13 |
struct foo // { dg-warning "final would enable devirtualization of 1 call" } |
| 14 |
{ |
| 15 |
static int count; |
| 16 |
void print (int i, int j) { printf ("foo[%d][%d] = %d\n", i, j, x); } |
| 17 |
int x; |
| 18 |
foo () { |
| 19 |
x = count++; |
| 20 |
printf("this %d = %x\n", x, (void *)this); |
| 21 |
} |
| 22 |
virtual ~foo () NOTHROW { |
| 23 |
printf("this %d = %x\n", x, (void *)this); |
| 24 |
--count; |
| 25 |
} |
| 26 |
}; |
| 27 |
int foo::count; |
| 28 |
|
| 29 |
|
| 30 |
int main () |
| 31 |
{ |
| 32 |
foo *arr[9]; |
| 33 |
for (int i = 0; i < 9; ++i) |
| 34 |
arr[i] = new foo(); |
| 35 |
if (foo::count != 9) |
| 36 |
return 1; |
| 37 |
for (int i = 0; i < 9; ++i) |
| 38 |
arr[i]->print(i / 3, i % 3); |
| 39 |
for (int i = 0; i < 9; ++i) |
| 40 |
delete arr[i]; |
| 41 |
if (foo::count != 0) |
| 42 |
return 1; |
| 43 |
return 0; |
| 44 |
} |