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 */
10 goto l
; /* { dg-error "used but not defined" "no label" } */
13 /* warnings for labels defined but not used, or declared but not defined */
17 l
: /* { dg-warning "defined but not used" "no goto 1" } */
18 m
: /* { dg-warning "defined but not used" "no goto 2" } */
24 __label__ l
; /* { dg-warning "declared but not defined" "only __label__" } */
28 /* can't have two labels with the same name in the same function */
31 l
: dummy(); /* { dg-error "previous definition" "prev def same scope" } */
32 l
: dummy(); /* { dg-error "duplicate label" "dup label same scope" } */
36 /* even at different scopes */
39 l
: dummy(); /* { dg-error "previous definition" "prev def diff scope" } */
41 l
: dummy(); /* { dg-error "duplicate label" "dup label diff scope" } */
46 /* but, with __label__, you can */
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 */
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 */
76 goto l
; /* { dg-error "used but not defined" "used, only __label__" } */
79 /* A nested function may not goto a label outside itself */
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 */
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
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" } */
123 /* not even with __label__ */
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__" } */
137 /* but if the outer label is declared with __label__, then a nested
138 function can goto that label (accomplishing a longjmp) */
142 void nest(void) { goto l
; }
148 /* and that means the nested function cannot have its own label with
149 the same name as an outer label declared with __label__ */
153 __label__ l
; /* { dg-error "previous declaration" "outer label decl" } */
156 l
: goto l
; /* { dg-error "duplicate label" "inner label defn" } */
163 /* unless the nested function uses __label__ too! */