| 1 |
// { dg-do compile } |
| 2 |
// { dg-options "-Wmissing-attributes" } |
| 3 |
|
| 4 |
#define ATTR(list) __attribute__ (list) |
| 5 |
|
| 6 |
/* Type attributes are normally absent in template functions, and the |
| 7 |
mere presence of any such attribute used to cause the |
| 8 |
-Wmissing-attributes checks, that checked for attributes typically |
| 9 |
associated with functions rather than types, to report any missing |
| 10 |
attributes twice: once for the specialization attribute list, once |
| 11 |
for its type attribute list. |
| 12 |
|
| 13 |
This test uses both decl and type attributes to exercise the code |
| 14 |
that avoids reporting duplicates, in ways that failed in the past |
| 15 |
but that were not covered in other tests. */ |
| 16 |
typedef void* ATTR ((alloc_size (1))) f_type (int); |
| 17 |
|
| 18 |
template <class T> |
| 19 |
f_type |
| 20 |
ATTR ((malloc)) |
| 21 |
missing_malloc; // { dg-message "missing primary template attribute .malloc." } |
| 22 |
|
| 23 |
template <> |
| 24 |
f_type |
| 25 |
missing_malloc<char>; // { dg-warning "explicit specialization .\[^\n\r\]+. may be missing attributes" } |
| 26 |
|
| 27 |
|
| 28 |
/* Check that even an attribute that appears in both lists (decl and |
| 29 |
type) in a template declaration is reported as missing only |
| 30 |
once. */ |
| 31 |
|
| 32 |
template <class T> |
| 33 |
f_type |
| 34 |
ATTR ((alloc_size (1))) // In both attr lists, decl's and type's. |
| 35 |
missing_alloc_size; // { dg-message "missing primary template attribute .alloc_size." } |
| 36 |
|
| 37 |
template <> |
| 38 |
void * |
| 39 |
missing_alloc_size<char>(int); // { dg-warning "explicit specialization .\[^\n\r\]+. may be missing attributes" } |
| 40 |
|
| 41 |
|
| 42 |
/* Check that even an attribute that appears in both lists (decl and |
| 43 |
type) is not reported as missing if it's present only in the type |
| 44 |
list. */ |
| 45 |
|
| 46 |
template <class T> |
| 47 |
f_type |
| 48 |
ATTR ((alloc_size (1))) // In both attr lists, decl's and type's. |
| 49 |
missing_nothing; |
| 50 |
|
| 51 |
template <> |
| 52 |
f_type |
| 53 |
missing_nothing<char>; |
| 54 |
|
| 55 |
|
| 56 |
/* For completeness, check that a type attribute is matched by a decl |
| 57 |
attribute in the specialization. */ |
| 58 |
|
| 59 |
template <class T> |
| 60 |
f_type |
| 61 |
missing_nothing2; |
| 62 |
|
| 63 |
template <> |
| 64 |
void * |
| 65 |
ATTR ((alloc_size (1))) |
| 66 |
missing_nothing2<char>(int); |