Break in loop expression-3

Florian Weimer fweimer@redhat.com
Wed Jul 24 13:36:00 GMT 2013


On 07/12/2013 06:16 PM, Ian Lance Taylor wrote:

>>      for(int i = 0;; ({break;}))

> 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.

This is not what's implemented in GCC 4.8.  This code compiles (both as 
C and C++):

int
f()
{
   int x = 1;
   while (1) {
     x = ({break; 5;});
   }
   return x;
}

The discrepancy between GCC and Clang is whether the expressions in the 
for statement header are considered nested within the loop.  I'm not 
sure if these aspects of statement expressions can be considered fully 
fleshed out.

-- 
Florian Weimer / Red Hat Product Security Team



More information about the Gcc-help mailing list