| 1 |
// Bug c++/83871 - wrong code due to attributes on distinct template |
| 2 |
// specializations |
| 3 |
// Test to verify that an explicit function template specifialization |
| 4 |
// does not "inherit" attribute nonnull from an argument declared with |
| 5 |
// one in the primary template. |
| 6 |
// { dg-do compile } |
| 7 |
// { dg-options "-O -Wall -fdump-tree-optimized -fdelete-null-pointer-checks" } |
| 8 |
|
| 9 |
template <class T> |
| 10 |
void* __attribute__ ((returns_nonnull)) |
| 11 |
g (); |
| 12 |
|
| 13 |
template <> |
| 14 |
void* |
| 15 |
g<int>(); |
| 16 |
|
| 17 |
extern void g_void_returns_nonnull (); |
| 18 |
extern void g_int_may_return_null (); |
| 19 |
|
| 20 |
void test_returns_nonnull () |
| 21 |
{ |
| 22 |
void *p = g<void>(); |
| 23 |
if (!p) |
| 24 |
g_void_returns_nonnull (); |
| 25 |
|
| 26 |
(void)&p; |
| 27 |
} |
| 28 |
|
| 29 |
void test_may_return_null () |
| 30 |
{ |
| 31 |
void *p = g<int>(); |
| 32 |
if (!p) |
| 33 |
g_int_may_return_null (); |
| 34 |
|
| 35 |
(void)&p; |
| 36 |
} |
| 37 |
|
| 38 |
|
| 39 |
// Verify that the call to g_void_returns_nonnull() is eliminated but |
| 40 |
// the call to g_int_may_return_null() is retained. |
| 41 |
// { dg-final { scan-tree-dump-not "g_void_returns_nonnull" "optimized" } } |
| 42 |
// { dg-final { scan-tree-dump-times "g_int_may_return_null" 1 "optimized" } } |