1 // { dg-do compile }
2 // { dg-options "-Wunused" }
3 
4 template <int N>
5 void
f1(void)6 f1 (void)
7 {
8   int a;	// { dg-warning "set but not used" }
9   int b;
10   int c;
11   c = 1;
12   a = b = c;
13 }
14 
15 template <int N>
16 void
f2(int x)17 f2 (int x)
18 {
19   int a;	// { dg-warning "set but not used" }
20   int b;
21   int c;	// { dg-warning "set but not used" }
22   c = (a = x, b = x);
23 }
24 
25 template <int N>
26 int
f3(int x)27 f3 (int x)
28 {
29   int a;
30   return a = x;
31 }
32 
33 template <int N>
34 int
f4(int x)35 f4 (int x)
36 {
37   int a;
38   a = x;
39   return a;
40 }
41 
42 template <int N>
43 void
f5(int x)44 f5 (int x)
45 {
46   int a[2];	// { dg-warning "set but not used" }
47   int b;
48   int *c, d[2];
49   c = d;
50   b = x;
51   a[b] = 1;
52   c[b] = 1;
53 }
54 
55 template <int N>
56 int
f6(int x)57 f6 (int x)
58 {
59   int a[2];
60   int b;
61   b = x;
62   a[b] = 1;
63   return a[b];
64 }
65 
66 template <int N>
67 void
f7(int x,int * p)68 f7 (int x, int *p)
69 {
70   int *a[2];
71   a[x] = p;
72   a[x][x] = x;
73 }
74 
75 struct S { int i; };
76 
77 template <int N>
78 void
f8(void)79 f8 (void)
80 {
81   struct S s;	// { dg-warning "set but not used" }
82   s.i = 6;
83 }
84 
85 template <int N>
86 int
f9(void)87 f9 (void)
88 {
89   struct S s;
90   s.i = 6;
91   return s.i;
92 }
93 
94 template <int N>
95 struct S
f10(void)96 f10 (void)
97 {
98   struct S s;
99   s.i = 6;
100   return s;
101 }
102 
103 extern int foo11 (int *);
104 
105 template <int N>
106 void
f11(void)107 f11 (void)
108 {
109   int a[2];
110   foo11 (a);
111 }
112 
113 template <int N>
114 void
f12(void)115 f12 (void)
116 {
117   int a;
118   a = 1;
119   a;	// { dg-warning "statement has no effect" }
120 }
121 
122 template <int N>
123 void
f13(void (* x)(void))124 f13 (void (*x) (void))
125 {
126   void (*a) (void);
127   a = x;
128   a ();
129 }
130 
131 template <int N>
132 void
f14(void (* x)(void))133 f14 (void (*x) (void))
134 {
135   void (*a) (void);	// { dg-warning "set but not used" }
136   a = x;
137 }
138 
139 extern void foo15 (int *);
140 
141 template <int N>
142 void
f15(void)143 f15 (void)
144 {
145   int a[10];
146   int *b = a + 2;
147   foo15 (b);
148 }
149 
150 extern void foo16 (int **);
151 
152 template <int N>
153 void
f16(void)154 f16 (void)
155 {
156   int a[10];
157   int *b[] = { a, a + 2 };
158   foo16 (b);
159 }
160 
161 template <int N>
162 void
f17(int x)163 f17 (int x)
164 {
165   long a;	// { dg-warning "set but not used" }
166   int b;
167   a = b = x;
168 }
169 
170 template <int N>
171 void
f18(int x)172 f18 (int x)
173 {
174   int a;	// { dg-warning "set but not used" }
175   int b;
176   a = (char) (b = x);
177 }
178 
179 template <int N>
180 int
f19(int x,int y,int z)181 f19 (int x, int y, int z)
182 {
183   int a;
184   int b;
185   a = x;
186   b = y;
187   return z ? a : b;
188 }
189 
190 template <int N>
191 int *
f20(int x)192 f20 (int x)
193 {
194   static int a[] = { 3, 4, 5, 6 };
195   static int b[] = { 4, 5, 6, 7 };
196   static int c[] = { 5, 6, 7, 8 };	// { dg-warning "set but not used" }
197   c[1] = 1;
198   return x ? a : b;
199 }
200 
201 S s;
202 
203 void
test()204 test ()
205 {
206   int i = 0;
207   f1<0> ();
208   f2<0> (0);
209   (void) f3<0> (0);
210   (void) f4<0> (0);
211   f5<0> (0);
212   (void) f6<0> (0);
213   f7<0> (0, &i);
214   f8<0> ();
215   (void) f9<0> ();
216   s = f10<0> ();
217   f11<0> ();
218   f12<0> ();
219   f13<0> (f1<0>);
220   f14<0> (f1<0>);
221   f15<0> ();
222   f16<0> ();
223   f17<0> (0);
224   f18<0> (0);
225   (void) f19<0> (0, 0, 0);
226   (void) f20<0> (0);
227 }
228