| 1 |
// Bug c++/83871 - wrong code due to attributes on distinct template |
| 2 |
// specializations |
| 3 |
// Test to verify that an explicit template specifialization does not |
| 4 |
// "inherit" attribute nothrow from a primary template declared with one. |
| 5 |
// { dg-do compile } |
| 6 |
// { dg-options "-O -Wall -fdump-tree-optimized" } |
| 7 |
|
| 8 |
template <class T> |
| 9 |
void __attribute__ ((nothrow)) |
| 10 |
f (); |
| 11 |
|
| 12 |
template <> |
| 13 |
void f<int>(); |
| 14 |
|
| 15 |
void f_void_nothrow (); |
| 16 |
void f_int_maythrow (); |
| 17 |
|
| 18 |
void fv (void) |
| 19 |
{ |
| 20 |
try |
| 21 |
{ |
| 22 |
f<void>(); |
| 23 |
} |
| 24 |
catch (...) // cannot be be reached |
| 25 |
{ |
| 26 |
f_void_nothrow (); // should be eliminated |
| 27 |
} |
| 28 |
} |
| 29 |
|
| 30 |
|
| 31 |
void fi (void) |
| 32 |
{ |
| 33 |
try |
| 34 |
{ |
| 35 |
f<int>(); |
| 36 |
} |
| 37 |
catch (...) // may be reached |
| 38 |
{ |
| 39 |
f_int_maythrow (); // must not be eliminated |
| 40 |
} |
| 41 |
} |
| 42 |
|
| 43 |
// Verify that the call to f_void_nothrow() is eliminated but |
| 44 |
// the call to f_int_maythrow() is retained. |
| 45 |
// { dg-final { scan-tree-dump-not "f_void_nothrow" "optimized" } } |
| 46 |
// { dg-final { scan-tree-dump-times "f_int_maythrow" 1 "optimized" } } |