| 1 |
// Bug c++/83503 - bogus -Wattributes for const and pure on function template |
| 2 |
// specialization |
| 3 |
// Test to verify that an explicit template specifialization does not |
| 4 |
// "inherit" attribute malloc from a primary template declared with one. |
| 5 |
// { dg-do compile } |
| 6 |
// { dg-options "-O -Wall -fdump-tree-optimized" } |
| 7 |
|
| 8 |
template <class> |
| 9 |
void* __attribute__ ((malloc)) |
| 10 |
fmalloc (unsigned); |
| 11 |
|
| 12 |
template <> |
| 13 |
void* |
| 14 |
fmalloc<int>(unsigned); // { dg-warning "may be missing attributes" } |
| 15 |
|
| 16 |
static char a[8]; |
| 17 |
|
| 18 |
void fmalloc_void_malloc (); |
| 19 |
void fmalloc_int_not_malloc (); |
| 20 |
|
| 21 |
void test_fmalloc_primary (void) |
| 22 |
{ |
| 23 |
void *p = fmalloc<void>(1); |
| 24 |
if (!p) |
| 25 |
return; |
| 26 |
|
| 27 |
if (p == a) // must be false |
| 28 |
fmalloc_void_malloc (); // should be eliminated |
| 29 |
|
| 30 |
// Verify that the call to fmalloc_void_malloc() is eliminated. |
| 31 |
// { dg-final { scan-tree-dump-not "fmalloc_void_malloc" "optimized" } } |
| 32 |
} |
| 33 |
|
| 34 |
|
| 35 |
void test_fmalloc_spec_none (void) |
| 36 |
{ |
| 37 |
void *p = fmalloc<int>(1); |
| 38 |
if (!p) |
| 39 |
return; |
| 40 |
|
| 41 |
if (p == a) // can be true |
| 42 |
fmalloc_int_not_malloc (); // must not be eliminated |
| 43 |
|
| 44 |
// Verify that the call to fmalloc_int_not_malloc() is retained. |
| 45 |
// { dg-final { scan-tree-dump-times "fmalloc_int_not_malloc" 1 "optimized" } } |
| 46 |
} |
| 47 |
|
| 48 |
template <> |
| 49 |
void* |
| 50 |
fmalloc<long>(unsigned); // { dg-warning "may be missing attributes" } |
| 51 |
|
| 52 |
template <> |
| 53 |
void* __attribute__ ((malloc)) |
| 54 |
fmalloc<long>(unsigned); |
| 55 |
|
| 56 |
void fmalloc_long_malloc (); |
| 57 |
|
| 58 |
void test_fmalloc_spec_malloc (void) |
| 59 |
{ |
| 60 |
void *p = fmalloc<long>(1); |
| 61 |
if (!p) |
| 62 |
return; |
| 63 |
|
| 64 |
if (p == a) // can be true |
| 65 |
fmalloc_long_malloc (); // must not be eliminated |
| 66 |
|
| 67 |
// Verify that the call to fmalloc_long_malloc() is eliminated. |
| 68 |
// { dg-final { scan-tree-dump-not "fmalloc_long_malloc" "optimized" } } |
| 69 |
} |