diff options
Diffstat (limited to 'clang/test/Sema/labeled-break-continue.c')
| -rw-r--r-- | clang/test/Sema/labeled-break-continue.c | 161 |
1 files changed, 161 insertions, 0 deletions
diff --git a/clang/test/Sema/labeled-break-continue.c b/clang/test/Sema/labeled-break-continue.c new file mode 100644 index 000000000000..78f81c484c3d --- /dev/null +++ b/clang/test/Sema/labeled-break-continue.c @@ -0,0 +1,161 @@ +// RUN: %clang_cc1 -std=c2y -verify -fsyntax-only -fblocks %s +// RUN: %clang_cc1 -std=c23 -verify -fsyntax-only -fblocks -fnamed-loops %s +// RUN: %clang_cc1 -x c++ -verify -fsyntax-only -fblocks -fnamed-loops %s + +void f1() { + l1: while (true) { + break l1; + continue l1; + } + + l2: for (;;) { + break l2; + continue l2; + } + + l3: do { + break l3; + continue l3; + } while (true); + + l4: switch (1) { + case 1: + break l4; + } +} + +void f2() { + l1:; + break l1; // expected-error {{'break' label does not name an enclosing loop or 'switch'}} + continue l1; // expected-error {{'continue' label does not name an enclosing loop}} + + l2: while (true) { + break l1; // expected-error {{'break' label does not name an enclosing loop or 'switch'}} + continue l1; // expected-error {{'continue' label does not name an enclosing loop}} + } + + while (true) { + break l2; // expected-error {{'break' label does not name an enclosing loop or 'switch'}} + continue l2; // expected-error {{'continue' label does not name an enclosing loop}} + } + + break l3; // expected-error {{'break' label does not name an enclosing loop or 'switch'}} + continue l3; // expected-error {{'continue' label does not name an enclosing loop}} + l3: while (true) {} +} + +void f3() { + a: b: c: d: while (true) { + break a; // expected-error {{'break' label does not name an enclosing loop or 'switch'}} + break b; // expected-error {{'break' label does not name an enclosing loop or 'switch'}} + break c; // expected-error {{'break' label does not name an enclosing loop or 'switch'}} + break d; + + continue a; // expected-error {{'continue' label does not name an enclosing loop}} + continue b; // expected-error {{'continue' label does not name an enclosing loop}} + continue c; // expected-error {{'continue' label does not name an enclosing loop}} + continue d; + + e: while (true) { + break a; // expected-error {{'break' label does not name an enclosing loop or 'switch'}} + break b; // expected-error {{'break' label does not name an enclosing loop or 'switch'}} + break c; // expected-error {{'break' label does not name an enclosing loop or 'switch'}} + break d; + break e; + + continue a; // expected-error {{'continue' label does not name an enclosing loop}} + continue b; // expected-error {{'continue' label does not name an enclosing loop}} + continue c; // expected-error {{'continue' label does not name an enclosing loop}} + continue d; + continue e; + } + + break e; // expected-error {{'break' label does not name an enclosing loop or 'switch'}} + continue e; // expected-error {{'continue' label does not name an enclosing loop}} + } +} + +void f4() { + a: switch (1) { + case 1: { + continue a; // expected-error {{label of 'continue' refers to a switch statement}} + } + } +} + +void f5() { + a: { + break a; // expected-error {{'break' label does not name an enclosing loop or 'switch'}} + } + + b: { + while (true) + break b; // expected-error {{'break' label does not name an enclosing loop or 'switch'}} + } +} + +void f6() { + a: while (({ + break a; // expected-error {{'break' label does not name an enclosing loop or 'switch'}} + continue a; // expected-error {{'continue' label does not name an enclosing loop}} + 1; + })) { + ({ break a; }); + ({ continue a; }); + } + + b: for ( + int x = ({ + break b; // expected-error {{'break' label does not name an enclosing loop or 'switch'}} + continue b; // expected-error {{'continue' label does not name an enclosing loop}} + 1; + }); + ({ + break b; // expected-error {{'break' label does not name an enclosing loop or 'switch'}} + continue b; // expected-error {{'continue' label does not name an enclosing loop}} + 1; + }); + (void) ({ + break b; // expected-error {{'break' label does not name an enclosing loop or 'switch'}} + continue b; // expected-error {{'continue' label does not name an enclosing loop}} + 1; + }) + ) { + ({ break b; }); + ({ continue b; }); + } + + c: do { + ({ break c; }); + ({ continue c; }); + } while (({ + break c; // expected-error {{'break' label does not name an enclosing loop or 'switch'}} + continue c; // expected-error {{'continue' label does not name an enclosing loop}} + 1; + })); + + d: switch (({ + break d; // expected-error {{'break' label does not name an enclosing loop or 'switch'}} + continue d; // expected-error {{'continue' label does not name an enclosing loop}} + 1; + })) { + case 1: { + ({ break d; }); + ({ continue d; }); // expected-error {{label of 'continue' refers to a switch statement}} + } + } +} + +void f7() { + a: while (true) { + (void) ^{ + break a; // expected-error {{'break' label does not name an enclosing loop or 'switch'}} + continue a; // expected-error {{'continue' label does not name an enclosing loop}} + }; + } + + while (true) { + break c; // expected-error {{'break' label does not name an enclosing loop or 'switch'}} + continue d; // expected-error {{'continue' label does not name an enclosing loop}} + } +} |
