[LLVMdev] Break in loop expression-3

Eli Friedman eli.friedman at gmail.com
Fri Jul 12 13:59:09 PDT 2013


On Fri, Jul 12, 2013 at 12:08 PM, Alex Markin <alexanius at gmail.com> wrote:
> Hello everyone.
>
> 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;}))
>
> I asked gcc developers about that fact, they answered that gcc is
> correct here, because statement expressions don't inherit the
> surrounding context.

That's simply wrong.

> So, it seems to be an llvm bug.

This is essentially the same as http://llvm.org/bugs/show_bug.cgi?id=8880 .

-Eli



More information about the llvm-dev mailing list