Fix ICE in substring-handling building 502.gcc_r (PR 87562)
[official-gcc.git] / gcc / testsuite / c-c++-common / Wunused-var-1.c
blobef8f6d4546a0c0a848dbf519dc0ece1dc4436e08
1 /* { dg-do compile } */
2 /* { dg-options "-Wunused" } */
4 void
5 f1 (void)
7 int a; /* { dg-warning "set but not used" } */
8 int b;
9 int c;
10 c = 1;
11 a = b = c;
14 void
15 f2 (int x)
17 int a; /* { dg-warning "set but not used" } */
18 int b;
19 int c; /* { dg-warning "set but not used" } */
20 c = (a = x, b = x);
23 int
24 f3 (int x)
26 int a;
27 return a = x;
30 int
31 f4 (int x)
33 int a;
34 a = x;
35 return a;
38 void
39 f5 (int x)
41 int a[2]; /* { dg-warning "set but not used" } */
42 int b;
43 int *c, d[2];
44 c = d;
45 b = x;
46 a[b] = 1;
47 c[b] = 1;
50 int
51 f6 (int x)
53 int a[2];
54 int b;
55 b = x;
56 a[b] = 1;
57 return a[b];
60 void
61 f7 (int x, int *p)
63 int *a[2];
64 a[x] = p;
65 a[x][x] = x;
68 struct S { int i; };
70 void
71 f8 (void)
73 struct S s; /* { dg-warning "set but not used" } */
74 s.i = 6;
77 int
78 f9 (void)
80 struct S s;
81 s.i = 6;
82 return s.i;
85 struct S
86 f10 (void)
88 struct S s;
89 s.i = 6;
90 return s;
93 extern int foo11 (int *);
95 void
96 f11 (void)
98 int a[2];
99 foo11 (a);
102 void
103 f12 (void)
105 int a;
106 a = 1;
107 a; /* { dg-warning "no effect" } */
110 void
111 f13 (void (*x) (void))
113 void (*a) (void);
114 a = x;
115 a ();
118 void
119 f14 (void (*x) (void))
121 void (*a) (void); /* { dg-warning "set but not used" } */
122 a = x;
125 extern void foo15 (int *);
127 void
128 f15 (void)
130 int a[10];
131 int *b = a + 2;
132 foo15 (b);
135 extern void foo16 (int **);
137 void
138 f16 (void)
140 int a[10];
141 int *b[] = { a, a + 2 };
142 foo16 (b);
145 void
146 f17 (int x)
148 long a; /* { dg-warning "set but not used" } */
149 int b;
150 a = b = x;
153 void
154 f18 (int x)
156 int a; /* { dg-warning "set but not used" } */
157 int b;
158 a = (char) (b = x);
162 f19 (int x, int y, int z)
164 int a;
165 int b;
166 a = x;
167 b = y;
168 return z ? a : b;
171 int *
172 f20 (int x)
174 static int a[] = { 3, 4, 5, 6 };
175 static int b[] = { 4, 5, 6, 7 };
176 static int c[] = { 5, 6, 7, 8 }; /* { dg-warning "set but not used" } */
177 c[1] = 1;
178 return x ? a : b;