This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Break in loop expression-3


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]