On Thu, Jul 11, 2013 at 11:17 PM, Alex Markin <alexanius@xxxxxxxxx> wrote: > > I've noticed the difference in gcc and llvm behaviour with the following code: > > $ cat test.c > #include <stdio.h> > int main() > { > for(int i = 0;; ({break;})) > printf("Hello, world\n"); > } > > $ clang test.c -pedantic && ./a.out > test.c:5:22: warning: use of GNU statement expression extension [-Wgnu] > for(int i = 0;; ({break;})) > ^ > 1 warning generated. > Hello, world > > $ gcc test.c -std=gnu11 -pedantic && ./a.out > test.c: In function 'main': > test.c:5:23: error: break statement not within loop or switch > for(int i = 0;; ({break;})) > ^ > test.c:5:21: warning: ISO C forbids braced-groups within expressions > [-Wpedantic] > for(int i = 0;; ({break;})) > > > So, llvm thinks that this is GNU extension (seems like it really is), > but compiles it, and gcc does not, even if the standard is specified > as gnu11. Is it a bug? Yes. But probably you wanted to know whether it is a bug in LLVM or in GCC. It's a bug in LLVM. You can't use break in a statement expression to break out of a loop that is not in the statement expression. Statement expressions are their own thing; they don't inherit the surrounding context, except that using a goto statement to a label outside the statement expression is permitted. Ian