Fix broken MinGW build of gcc.c
[official-gcc.git] / gcc / testsuite / g++.dg / warn / Wunused-var-26.C
blobb3e020b600781f42b0b1123bd7f4911bfd79852d
1 // PR c++/79548 - missing -Wunused-variable on a typedef'd variable
2 // in a function template
3 // { dg-do compile }
4 // { dg-options "-Wunused" }
7 #define UNUSED __attribute__ ((unused))
9 template <class T>
10 void f_int ()
12   T t;                        // { dg-warning "unused variable" }
14   typedef T U;
15   U u;                        // { dg-warning "unused variable" }
18 template void f_int<int>();
21 template <class T>
22 void f_intptr ()
24   T *t = 0;                   // { dg-warning "unused variable" }
26   typedef T U;
27   U *u = 0;                   // { dg-warning "unused variable" }
30 template void f_intptr<int>();
33 template <class T>
34 void f_var_unused ()
36   // The variable is marked unused.
37   T t UNUSED;
39   typedef T U;
40   U u UNUSED;
43 template void f_var_unused<int>();
46 template <class T>
47 void f_var_type_unused ()
49   // The variable's type is marked unused.
50   T* UNUSED t = new T;   // { dg-bogus "unused variable" "bug 79585" { xfail *-*-* } }
52   typedef T U;
53   U* UNUSED u = new U;   // { dg-bogus "unused variable" "bug 79585" { xfail *-*-* } }
55   typedef T UNUSED U;
56   U v = U ();   // { dg-bogus "unused variable" "bug 79585" }
59 template void f_var_type_unused<int>();
62 struct A { int i; };
64 template <class T>
65 void f_A ()
67   T t;                        // { dg-warning "unused variable" }
69   typedef T U;
70   U u;                        // { dg-warning "unused variable" }
73 template void f_A<A>();
76 template <class T>
77 void f_A_unused ()
79   T t UNUSED;
81   typedef T U;
82   U u UNUSED;
85 template void f_A_unused<A>();
88 struct B { B (); };
90 template <class T>
91 void f_B ()
93   T t;
95   typedef T U;
96   U u;
99 template void f_B<B>();
102 struct NonTrivialDtor { ~NonTrivialDtor (); };
104 template <class T>
105 void f_with_NonTrivialDtor ()
107   // Expect no warnings when instantiated on a type with a non-trivial
108   // destructor.
109   T t;
111   typedef T U;
112   U u;
115 template void f_with_NonTrivialDtor<NonTrivialDtor>();
118 struct D { NonTrivialDtor b; };
120 template <class T>
121 void f_D ()
123   // Same as f_with_NonTrivialDtor but with a class that has a member
124   // with a non-trivial dtor.
125   T t;
127   typedef T U;
128   U u;
131 template void f_D<D>();
134 struct UNUSED DeclaredUnused { };
136 template <class T>
137 void f_with_unused ()
139   // Expect no warnings when instantiatiated on a type declared
140   // with attribute unused.
141   T t;
143   typedef T U;
144   U u;
147 template void f_with_unused<DeclaredUnused>();