No empty .Rs/.Re
[netbsd-mini2440.git] / gnu / dist / gcc4 / gcc / testsuite / gcc.dg / noncompile / label-1.c
blobe9bde7b3b7b6ffdd9ac8830323b9cc86ebe91628
1 /* Test various diagnostics of ill-formed constructs involving labels. */
2 /* { dg-do compile } */
3 /* { dg-options "-Wunused" } */
5 extern void dummy(void);
7 /* labels must be defined */
8 void a(void)
10 goto l; /* { dg-error "used but not defined" "no label" } */
13 /* warnings for labels defined but not used, or declared but not defined */
14 void b(void)
16 __label__ l;
17 l: /* { dg-warning "defined but not used" "no goto 1" } */
18 m: /* { dg-warning "defined but not used" "no goto 2" } */
19 dummy();
22 void c(void)
24 __label__ l; /* { dg-warning "declared but not defined" "only __label__" } */
25 dummy();
28 /* can't have two labels with the same name in the same function */
29 void d(void)
31 l: dummy(); /* { dg-error "previous definition" "prev def same scope" } */
32 l: dummy(); /* { dg-error "duplicate label" "dup label same scope" } */
33 goto l;
36 /* even at different scopes */
37 void e(void)
39 l: dummy(); /* { dg-error "previous definition" "prev def diff scope" } */
41 l: dummy(); /* { dg-error "duplicate label" "dup label diff scope" } */
43 goto l;
46 /* but, with __label__, you can */
47 void f(void)
49 l: dummy();
51 __label__ l;
52 l: dummy(); /* { dg-warning "defined but not used" "unused shadow 1" } */
54 goto l; /* this reaches the outer l */
57 /* a __label__ is not visible outside its scope */
58 void g(void)
60 dummy();
62 __label__ l;
63 l: dummy();
64 goto l;
66 goto l; /* { dg-error "used but not defined" "label ref out of scope" } */
69 /* __label__ can appear at top level of a function, too...
70 ... but doesn't provide a definition of the label */
71 void h(void)
73 __label__ l;
74 dummy ();
76 goto l; /* { dg-error "used but not defined" "used, only __label__" } */
79 /* A nested function may not goto a label outside itself */
80 void i(void)
82 auto void nest(void);
84 l: nest();
86 void nest(void)
88 goto l; /* { dg-error "used but not defined" "nest use outer label" } */
91 goto l; /* reaches the outer l */
94 /* which means that a nested function may have its own label with the
95 same name as the outer function */
96 void j(void)
98 auto void nest(void);
100 l: nest();
102 void nest(void)
104 l: dummy(); /* { dg-warning "defined but not used" "nest label same name" } */
107 goto l; /* reaches the outer l */
110 /* and, turnabout, an outer function may not goto a label in a nested
111 function */
112 void k(void)
114 void nest(void)
116 l: dummy(); /* { dg-warning "defined but not used" "outer use nest label" } */
119 goto l; /* { dg-error "used but not defined" "outer use nest label" } */
120 nest();
123 /* not even with __label__ */
124 void l(void)
126 void nest(void)
128 __label__ l;
129 l: dummy(); /* { dg-warning "defined but not used" "outer use nest __label__" } */
132 goto l; /* { dg-error "used but not defined" "outer use nest __label__" } */
133 nest();
137 /* but if the outer label is declared with __label__, then a nested
138 function can goto that label (accomplishing a longjmp) */
139 void m(void)
141 __label__ l;
142 void nest(void) { goto l; }
143 nest();
144 dummy();
148 /* and that means the nested function cannot have its own label with
149 the same name as an outer label declared with __label__ */
151 void n(void)
153 __label__ l; /* { dg-error "previous declaration" "outer label decl" } */
154 void nest(void)
156 l: goto l; /* { dg-error "duplicate label" "inner label defn" } */
160 nest();
163 /* unless the nested function uses __label__ too! */
164 void o(void)
166 __label__ l;
167 void nest(void)
169 __label__ l;
170 l: goto l;
173 l: goto l;
174 nest();