summaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/warn/Wunused-var-26.C
blob: b3e020b600781f42b0b1123bd7f4911bfd79852d (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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
// PR c++/79548 - missing -Wunused-variable on a typedef'd variable
// in a function template
// { dg-do compile }
// { dg-options "-Wunused" }


#define UNUSED __attribute__ ((unused))

template <class T>
void f_int ()
{
  T t;                        // { dg-warning "unused variable" }

  typedef T U;
  U u;                        // { dg-warning "unused variable" }
}

template void f_int<int>();


template <class T>
void f_intptr ()
{
  T *t = 0;                   // { dg-warning "unused variable" }

  typedef T U;
  U *u = 0;                   // { dg-warning "unused variable" }
}

template void f_intptr<int>();


template <class T>
void f_var_unused ()
{
  // The variable is marked unused.
  T t UNUSED;

  typedef T U;
  U u UNUSED;
}

template void f_var_unused<int>();


template <class T>
void f_var_type_unused ()
{
  // The variable's type is marked unused.
  T* UNUSED t = new T;   // { dg-bogus "unused variable" "bug 79585" { xfail *-*-* } }

  typedef T U;
  U* UNUSED u = new U;   // { dg-bogus "unused variable" "bug 79585" { xfail *-*-* } }

  typedef T UNUSED U;
  U v = U ();   // { dg-bogus "unused variable" "bug 79585" }
}

template void f_var_type_unused<int>();


struct A { int i; };

template <class T>
void f_A ()
{
  T t;                        // { dg-warning "unused variable" }

  typedef T U;
  U u;                        // { dg-warning "unused variable" }
}

template void f_A<A>();


template <class T>
void f_A_unused ()
{
  T t UNUSED;

  typedef T U;
  U u UNUSED;
}

template void f_A_unused<A>();


struct B { B (); };

template <class T>
void f_B ()
{
  T t;

  typedef T U;
  U u;
}

template void f_B<B>();


struct NonTrivialDtor { ~NonTrivialDtor (); };

template <class T>
void f_with_NonTrivialDtor ()
{
  // Expect no warnings when instantiated on a type with a non-trivial
  // destructor.
  T t;

  typedef T U;
  U u;
}

template void f_with_NonTrivialDtor<NonTrivialDtor>();


struct D { NonTrivialDtor b; };

template <class T>
void f_D ()
{
  // Same as f_with_NonTrivialDtor but with a class that has a member
  // with a non-trivial dtor.
  T t;

  typedef T U;
  U u;
}

template void f_D<D>();


struct UNUSED DeclaredUnused { };

template <class T>
void f_with_unused ()
{
  // Expect no warnings when instantiatiated on a type declared
  // with attribute unused.
  T t;

  typedef T U;
  U u;
}

template void f_with_unused<DeclaredUnused>();