teak-llvm/clang/test/Parser/bad-control.c
Serge Pavlov 09f9924acf Fix to PR8880 (clang dies processing a for loop)
Due to statement expressions supported as GCC extension, it is possible
to put 'break' or 'continue' into a loop/switch statement but outside
its body, for example:

    for ( ; ({ if (first) { first = 0; continue; } 0; }); )

This code is rejected by GCC if compiled in C mode but is accepted in C++
code. GCC bug 44715 tracks this discrepancy. Clang used code generation
that differs from GCC in both modes: only statement of the third
expression of 'for' behaves as if it was inside loop body.

This change makes code generation more close to GCC, considering 'break'
or 'continue' statement in condition and increment expressions of a
loop as it was inside the loop body. It also adds error for the cases
when 'break'/'continue' appear outside loop due to this syntax. If
code generation differ from GCC, warning is issued.

Differential Revision: http://llvm-reviews.chandlerc.com/D2518

llvm-svn: 199897
2014-01-23 15:05:00 +00:00

25 lines
674 B
C

/* RUN: %clang_cc1 -fsyntax-only -verify %s
*/
void foo() {
break; /* expected-error {{'break' statement not in loop or switch statement}} */
}
void foo2() {
continue; /* expected-error {{'continue' statement not in loop statement}} */
}
int pr8880_9 (int first) {
switch(({ if (first) { first = 0; break; } 1; })) { // expected-error {{'break' statement not in loop or switch statement}}
case 2: return 2;
default: return 0;
}
}
void pr8880_24() {
for (({break;});;); // expected-error {{'break' statement not in loop or switch statement}}
}
void pr8880_25() {
for (({continue;});;); // expected-error {{'continue' statement not in loop statement}}
}