1 // Origin PR c++/33255
2 // { dg-options "-Wunused" } <-- should trigger -Wunused-local-typedefs
3 // { dg-do compile }
4 
5 void
test_warn()6 test_warn()
7 {
8   typedef int foo; // { dg-warning "locally defined but not used" }
9 }
10 
11 struct S
12 {
13     typedef int T;
SS14     S() {}
SS15     S(int) {}
16 };
17 
18 template<class T>
19 struct ST
20 {
21     typedef T type;
STST22     ST (int) {}
STST23     ST () {}
24 };
25 
26 template<class T>
27 void
test0_tmpl(void)28 test0_tmpl(void)
29 {
30     typedef struct ST<T> foo;
31     foo(2);
32 }
33 
34 void
35 test0(void)
36 {
37     test0_tmpl<int>();
38 }
39 
40 void
41 test1(void)
42 {
43     typedef int foo;
44     ST<foo> a;
45 }
46 
47 
48 int
49 test2(void)
50 {
51     typedef S foo;
52     foo::T i = 0;
53     return i;
54 }
55 
56 template<class T>
57 void
58 test3_tmpl(void)
59 {
60     typedef struct ST<int> foo;
61     ST<int> v;
62     const foo __attribute__((unused))&var = v;
63 }
64 
65 void
66 test3(void)
67 {
68     test3_tmpl<int>();
69 }
70 
71 void
72 test4(void)
73 {
74   typedef int foo;
75   int __attribute__((unused))vec[1] = {sizeof (foo)};
76 }
77 
78 void
79 test5(void)
80 {
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;
88 
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);
97 }
98 
99 void
100 test6(void)
101 {
102   struct C0 {};
103   typedef C0 foo;
104   C0 *__attribute__((unused))v = new foo;
105 }
106 
107 template<class T, class U>
108 struct S7
109 {
110   void
111   f()
112   {
113     typedef int foo;
114     sizeof(foo);
115   }
116 };
117 
118 template<class T>
119 void
120 test7(void)
121 {
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;
126 }
127 
128 
129 template<class T, class U>
130 void
131 test8(void)
132 {
133   int f(S7<T, U>);
134   void g(int);
135   typedef T foo;
136   g(f(S7<foo, U>()));
137 }
138 
139 int
140 test9(void)
141 {
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;
146 }
147