PR lto/84212 - -Wno-* does not disable warnings from -flto link stage
[official-gcc.git] / gcc / testsuite / g++.dg / warn / Wunused-local-typedefs.C
blob73f7ec79ce1134b7ef39f6275b4fbe8294d3609b
1 // Origin PR c++/33255
2 // { dg-options "-Wunused" } <-- should trigger -Wunused-local-typedefs
3 // { dg-do compile }
5 void
6 test_warn()
8   typedef int foo; // { dg-warning "locally defined but not used" }
11 struct S
13     typedef int T;
14     S() {}
15     S(int) {}
18 template<class T>
19 struct ST
21     typedef T type;
22     ST (int) {}
23     ST () {}
26 template<class T>
27 void
28 test0_tmpl(void)
30     typedef struct ST<T> foo;
31     foo(2);
34 void
35 test0(void)
37     test0_tmpl<int>();
40 void
41 test1(void)
43     typedef int foo;
44     ST<foo> a;
48 int
49 test2(void)
51     typedef S foo;
52     foo::T i = 0;
53     return i;
56 template<class T>
57 void
58 test3_tmpl(void)
60     typedef struct ST<int> foo;
61     ST<int> v;
62     const foo __attribute__((unused))&var = v;
65 void
66 test3(void)
68     test3_tmpl<int>();
71 void
72 test4(void)
74   typedef int foo;
75   int __attribute__((unused))vec[1] = {sizeof (foo)};
78 void
79 test5(void)
81   typedef int T0;
82   typedef char T1;
83   typedef int* T2;
84   typedef unsigned T3;
85   struct C0 { virtual void f(void) {}};
86   struct C1 : C0 {};
87   typedef C0 T4;
89   int v0 = (T0) 2;
90   char __attribute__((unused)) v1 = static_cast<T1> (0);
91   if (reinterpret_cast<T2> (&v0));
92   unsigned* const c = 0;
93   unsigned* __attribute__((unused))v2 = const_cast<T3* const> (c);
94   C0 *__attribute__((unused))p0 = 0;
95   C1 *p1 = 0;
96   p0 = dynamic_cast<T4*> (p1);  
99 void
100 test6(void)
102   struct C0 {};
103   typedef C0 foo;
104   C0 *__attribute__((unused))v = new foo;
107 template<class T, class U>
108 struct S7
110   void
111   f()
112   {
113     typedef int foo;
114     sizeof(foo);
115   }
118 template<class T>
119 void
120 test7(void)
122   typedef typename ST<T>::T bar; // { dg-warning "locally defined but not used" }
123   typedef typename ST<T>::T foo; // We shouldn't warn for this one, as
124                                  // it's used below.
125   S7<int, foo> v;
129 template<class T, class U>
130 void
131 test8(void)
133   int f(S7<T, U>);
134   void g(int);
135   typedef T foo;
136   g(f(S7<foo, U>()));
140 test9(void)
142   struct s { typedef int foo;}; // { dg-warning "locally defined but not used" }
143   struct t { typedef int bar;};
144   t::bar b = 0;
145   return b;