PR c++/85553
[official-gcc.git] / gcc / testsuite / g++.dg / ext / attr-warning.C
blob6478efa8b831a2a1c931058af801a5ff8598ed5d
1 // Bug c++/83871 - wrong code due to attributes on distinct template
2 // specializations
3 // Test to verify that an explicit template specifialization does not
4 // "inherit" attribute warning from a primary template declared with
5 // it.
6 // { dg-do compile }
7 // { dg-options "-Wall" }
9 struct Special;
11 // Primary has no attributes here.
12 template <class T>
13 void fwarn_primary ();
15 // Uses of the primary template, including declarations of its
16 // specializations, should not be diagnosed until after it has
17 // been redeclared with attribute warning.
18 template <>
19 void fwarn_primary<Special> ();
21 void use_primary_before_warning ()
23   // Verify that uses of the primary are not diagnosed.
24   fwarn_primary<char>();
25   fwarn_primary<short>();
28 // Redeclare the primary with attribute warning.
29 template <class T>
30 void __attribute__ ((warning ("primary")))
31 fwarn_primary ();
33 // Attribute warning is special in that it only warns for functions
34 // that are actually used, not those that are only declared.
35 template <>
36 void fwarn_primary<double> ();
38 void use_primary_after_warning ()
40   // Verify that uses of the redeclared primary are diagnosed.
41   fwarn_primary<int>();           // { dg-warning "primary" }
42   fwarn_primary<long>();          // { dg-warning "primary" }
45 void use_special ()
47   // Verify that the use of the specializatoin is not diagnosed.
48   fwarn_primary<Special>();