aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/ext/attr-warning.C
blob: 6478efa8b831a2a1c931058af801a5ff8598ed5d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Bug c++/83871 - wrong code due to attributes on distinct template
// specializations
// Test to verify that an explicit template specifialization does not
// "inherit" attribute warning from a primary template declared with
// it.
// { dg-do compile }
// { dg-options "-Wall" }

struct Special;

// Primary has no attributes here.
template <class T>
void fwarn_primary ();

// Uses of the primary template, including declarations of its
// specializations, should not be diagnosed until after it has
// been redeclared with attribute warning.
template <>
void fwarn_primary<Special> ();

void use_primary_before_warning ()
{
  // Verify that uses of the primary are not diagnosed.
  fwarn_primary<char>();
  fwarn_primary<short>();
}

// Redeclare the primary with attribute warning.
template <class T>
void __attribute__ ((warning ("primary")))
fwarn_primary ();

// Attribute warning is special in that it only warns for functions
// that are actually used, not those that are only declared.
template <>
void fwarn_primary<double> ();

void use_primary_after_warning ()
{
  // Verify that uses of the redeclared primary are diagnosed.
  fwarn_primary<int>();           // { dg-warning "primary" }
  fwarn_primary<long>();          // { dg-warning "primary" }
}

void use_special ()
{
  // Verify that the use of the specializatoin is not diagnosed.
  fwarn_primary<Special>();
}