| 1 |
// PR c++/83871 - wrong code for attribute const and pure on distinct |
| 2 |
// template specializations |
| 3 |
// Test to verify that a declaration of an explicit specialization with |
| 4 |
// no attributes is diagnosed when the primary template is declared with |
| 5 |
// one or more attributes. The warning helps highlight a change in GCC |
| 6 |
// 8 from previous versions that copied the attributes from the primary |
| 7 |
// to the specialization. It also helps point out simply forgetting to |
| 8 |
// declare the specialization with an attribute. |
| 9 |
// { dg-do compile } |
| 10 |
// { dg-options "-Wmissing-attributes" } |
| 11 |
|
| 12 |
#define ATTR(list) __attribute__ (list) |
| 13 |
|
| 14 |
|
| 15 |
// Verify that a primary without attributes doesn't cause warnings. |
| 16 |
template <class T> void fnoattr (); |
| 17 |
|
| 18 |
template <> void fnoattr<void>(); |
| 19 |
template <> void ATTR ((cold)) fnoattr<int>(); |
| 20 |
template <> void ATTR ((hot)) fnoattr<double>(); |
| 21 |
|
| 22 |
// Verify that a noreturn primary also doesn't cause warnings. |
| 23 |
template <class T> int ATTR ((noreturn)) fnoreturn (); |
| 24 |
|
| 25 |
template <> int fnoreturn<void>(); |
| 26 |
template <> int ATTR ((cold)) fnoreturn<int>(); |
| 27 |
template <> int ATTR ((hot)) fnoreturn<double>(); |
| 28 |
|
| 29 |
|
| 30 |
template <class T> |
| 31 |
void* |
| 32 |
ATTR ((malloc, alloc_size (1))) |
| 33 |
missing_all (int); // { dg-message "missing primary template attributes \(.malloc., .alloc_size.|.alloc_size., .malloc.\)" } |
| 34 |
|
| 35 |
template <> |
| 36 |
void* |
| 37 |
missing_all<char>(int); // { dg-warning "explicit specialization .\[^\n\r\]+. may be missing attributes" } |
| 38 |
|
| 39 |
// Verify that specifying the same attributes in whatever order |
| 40 |
// doesn't trigger the warning, even when other attributes are |
| 41 |
// added. |
| 42 |
template <> |
| 43 |
void* |
| 44 |
ATTR ((alloc_size (1), malloc)) |
| 45 |
missing_all<char>(int); |
| 46 |
|
| 47 |
template <> |
| 48 |
void* |
| 49 |
ATTR ((alloc_size (1))) ATTR ((malloc)) ATTR ((returns_nonnull)) |
| 50 |
missing_all<char>(int); // T = char, same as above |
| 51 |
|
| 52 |
template <> |
| 53 |
void* |
| 54 |
ATTR ((hot)) ATTR ((alloc_size (1))) ATTR ((malloc)) |
| 55 |
missing_all<char>(int); // T = char, same as above |
| 56 |
|
| 57 |
// Verify that the following attributes suppress the warning. |
| 58 |
template <> void* ATTR ((error (""))) missing_all<short>(int); |
| 59 |
template <> void* ATTR ((deprecated)) missing_all<int>(int); |
| 60 |
template <> void* ATTR ((warning (""))) missing_all<double>(int); |
| 61 |
|
| 62 |
|
| 63 |
template <class T> |
| 64 |
void* |
| 65 |
ATTR ((malloc, alloc_size (1))) |
| 66 |
missing_malloc (int); // { dg-message "missing primary template attribute .malloc." } |
| 67 |
|
| 68 |
template <> |
| 69 |
void* |
| 70 |
ATTR ((alloc_size (1))) |
| 71 |
missing_malloc<char>(int); // { dg-warning "explicit specialization .\[^\n\r\]+. may be missing attributes" } |
| 72 |
|
| 73 |
template <> void* ATTR ((malloc, alloc_size (1))) missing_malloc<short>(int); |
| 74 |
template <> void* ATTR ((deprecated)) missing_malloc<int>(int); |
| 75 |
template <> void* ATTR ((error (""))) missing_malloc<long>(int); |
| 76 |
template <> void* ATTR ((warning (""))) missing_malloc<double>(int); |
| 77 |
|
| 78 |
template <class T> |
| 79 |
void* |
| 80 |
ATTR ((malloc, alloc_size (1))) |
| 81 |
missing_alloc_size (int, int); // { dg-message "missing primary template attribute .alloc_size." } |
| 82 |
|
| 83 |
template <> |
| 84 |
void* |
| 85 |
ATTR ((malloc)) |
| 86 |
missing_alloc_size<char>(int, int); // { dg-warning "explicit specialization .\[^\n\r\]+. may be missing attributes" } |
| 87 |
|
| 88 |
|
| 89 |
template <class T> |
| 90 |
void* |
| 91 |
ATTR ((nonnull (1))) |
| 92 |
missing_nonnull (void*); // { dg-message "missing primary template attribute .nonnull." } |
| 93 |
|
| 94 |
template <> |
| 95 |
void* |
| 96 |
ATTR ((malloc)) |
| 97 |
missing_nonnull<char>(void*); // { dg-warning "explicit specialization .\[^\n\r\]+. may be missing attributes" } |
| 98 |
|
| 99 |
template <> void* ATTR ((nonnull (1))) missing_nonnull<short>(void*); |
| 100 |
template <> void* ATTR ((deprecated)) missing_nonnull<int>(void*); |
| 101 |
template <> void* ATTR ((error (""))) missing_nonnull<long>(void*); |
| 102 |
template <> void* ATTR ((warning (""))) missing_nonnull<double>(void*); |