On Tue, Dec 10, 2013 at 10:16 PM, Florian Weimer <fwei...@redhat.com> wrote:
> On 12/10/2013 02:21 PM, Prathamesh Kulkarni wrote:
>>
>> The following code fails to compile with gcc-4.8.2.
>>
>> int main(void)
>> {
>>      while ( ({ break; 0; }) )
>>          ;
>>      return 0;
>> }
>>
>> foo.c:3:14: error: break statement not within loop or switch
>>     while ( ({ break; 0; }) )
>>                ^
>> Is this a compile-error or is it a bug in GCC ?
>> clang-3.2 seems to compile it.
>>
>> I came across a thread  on this issue
>> in context of for loop, but I couldn't get a definite answer.
>> http://gcc.gnu.org/ml/gcc-help/2013-07/msg00100.html
>
>
> There's also bug <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44715>.
Thanks for pointing it out.

>From the bug-report (comment 4):
Here is what the c++ standard says :
"The break statement shall occur only in an iteration-statement or a switch
statement and causes termination of the smallest enclosing iteration-statement
or switch statement; control passes to the statement following the terminated
statement, if any."
So the break (if the expression statement extension is activated) is considered
in the inner loop with this extension.

So I guess g++ should compile it ?
g++ rejects it too:
foo.cpp:3:14: error: break statement not within loop or switch
   while ( ({ break; 0; }) )

>
> I think it's fine to reject such code.
>
> --
> Florian Weimer / Red Hat Product Security Team

Thanks and Regards,
Prathamesh

Reply via email to