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.
10 // { dg-options "-Wmissing-attributes" }
12 #define ATTR(list) __attribute__ (list)
15 // Verify that a primary without attributes doesn't cause warnings.
16 template <class T> void fnoattr ();
18 template <> void fnoattr<void>();
19 template <> void ATTR ((cold)) fnoattr<int>();
20 template <> void ATTR ((hot)) fnoattr<double>();
22 // Verify that a noreturn primary also doesn't cause warnings.
23 template <class T> int ATTR ((noreturn)) fnoreturn ();
25 template <> int fnoreturn<void>();
26 template <> int ATTR ((cold)) fnoreturn<int>();
27 template <> int ATTR ((hot)) fnoreturn<double>();
32 ATTR ((malloc, alloc_size (1)))
33 missing_all (int); // { dg-message "missing primary template attributes \(.malloc., .alloc_size.|.alloc_size., .malloc.\)" }
37 missing_all<char>(int); // { dg-warning "explicit specialization .\[^\n\r\]+. may be missing attributes" }
39 // Verify that specifying the same attributes in whatever order
40 // doesn't trigger the warning, even when other attributes are
44 ATTR ((alloc_size (1), malloc))
45 missing_all<char>(int);
49 ATTR ((alloc_size (1))) ATTR ((malloc)) ATTR ((returns_nonnull))
50 missing_all<char>(int); // T = char, same as above
54 ATTR ((hot)) ATTR ((alloc_size (1))) ATTR ((malloc))
55 missing_all<char>(int); // T = char, same as above
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);
65 ATTR ((malloc, alloc_size (1)))
66 missing_malloc (int); // { dg-message "missing primary template attribute .malloc." }
70 ATTR ((alloc_size (1)))
71 missing_malloc<char>(int); // { dg-warning "explicit specialization .\[^\n\r\]+. may be missing attributes" }
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);
80 ATTR ((malloc, alloc_size (1)))
81 missing_alloc_size (int, int); // { dg-message "missing primary template attribute .alloc_size." }
86 missing_alloc_size<char>(int, int); // { dg-warning "explicit specialization .\[^\n\r\]+. may be missing attributes" }
92 missing_nonnull (void*); // { dg-message "missing primary template attribute .nonnull." }
97 missing_nonnull<char>(void*); // { dg-warning "explicit specialization .\[^\n\r\]+. may be missing attributes" }
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*);