OSDN Git Service

2012-05-16 Richard Guenther <rguenther@suse.de>
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / c-c++-common / Wunused-var-1.c
1 /* { dg-do compile } */
2 /* { dg-options "-Wunused" } */
3
4 void
5 f1 (void)
6 {
7   int a;        /* { dg-warning "set but not used" } */
8   int b;
9   int c;
10   c = 1;
11   a = b = c;
12 }
13
14 void
15 f2 (int x)
16 {
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);
21 }
22
23 int
24 f3 (int x)
25 {
26   int a;
27   return a = x;
28 }
29
30 int
31 f4 (int x)
32 {
33   int a;
34   a = x;
35   return a;
36 }
37
38 void
39 f5 (int x)
40 {
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;
48 }
49
50 int
51 f6 (int x)
52 {
53   int a[2];
54   int b;
55   b = x;
56   a[b] = 1;
57   return a[b];
58 }
59
60 void
61 f7 (int x, int *p)
62 {
63   int *a[2];
64   a[x] = p;
65   a[x][x] = x;
66 }
67
68 struct S { int i; };
69
70 void
71 f8 (void)
72 {
73   struct S s;   /* { dg-warning "set but not used" } */
74   s.i = 6;
75 }
76
77 int
78 f9 (void)
79 {
80   struct S s;
81   s.i = 6;
82   return s.i;
83 }
84
85 struct S
86 f10 (void)
87 {
88   struct S s;
89   s.i = 6;
90   return s;
91 }
92
93 extern int foo11 (int *);
94
95 void
96 f11 (void)
97 {
98   int a[2];
99   foo11 (a);
100 }
101
102 void
103 f12 (void)
104 {
105   int a;
106   a = 1;
107   a;    /* { dg-warning "no effect" } */
108 }
109
110 void
111 f13 (void (*x) (void))
112 {
113   void (*a) (void);
114   a = x;
115   a ();
116 }
117
118 void
119 f14 (void (*x) (void))
120 {
121   void (*a) (void);     /* { dg-warning "set but not used" } */
122   a = x;
123 }
124
125 extern void foo15 (int *);
126
127 void
128 f15 (void)
129 {
130   int a[10];
131   int *b = a + 2;
132   foo15 (b);
133 }
134
135 extern void foo16 (int **);
136
137 void
138 f16 (void)
139 {
140   int a[10];
141   int *b[] = { a, a + 2 };
142   foo16 (b);
143 }
144
145 void
146 f17 (int x)
147 {
148   long a;       /* { dg-warning "set but not used" } */
149   int b;
150   a = b = x;
151 }
152
153 void
154 f18 (int x)
155 {
156   int a;        /* { dg-warning "set but not used" } */
157   int b;
158   a = (char) (b = x);
159 }
160
161 int
162 f19 (int x, int y, int z)
163 {
164   int a;
165   int b;
166   a = x;
167   b = y;
168   return z ? a : b;
169 }
170
171 int *
172 f20 (int x)
173 {
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;
179 }