------- Comment #4 from ecyrbe at gmail dot com 2010-07-06 05:28 ------- (In reply to comment #3) > Subject: Re: Break in increment expression of "for" statement > inconsistent with g++ > > On Tue, 29 Jun 2010, pinskia at gmail dot com wrote: > > > What does a break with a statement expression do for each frontend? Is > > it even valid to have a break there(without a statement expression)? > > The relevant contexts have expressions, so without statement expressions > it's not possible to have break there. The C standard (I haven't checked > C++) requires break (and continue, which probably has much the same issue) > to be in a loop or switch body - but being elsewhere in the loop than its > body isn't possible in standard C anyway. When I was fixing statement > expression issues with jumps, and defining exactly what was permitted (bug > 772), I didn't think of this particular issue. >
As i said in the clang bug tracker who triggered this issue initially : 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. And now here is what the c99 standard says : "A break statement shall appear only in or as a switch body or loop body" But in C, the loop body does not contain the expression statement. So the break applie only to the outer loop in C. The result is that gcc is correct in this behavior. C++ and C should differ in this matter. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44715