Hello.

I tried to do

for (;; ({ break; }))
        printf("Hello\n");

and got an error message:

error: break statement not within loop or switch

when compiling it as C. Given that 9899:1999 §6.8.6.3 says that a break
statement only shall appear in or as a switch or loop body that is expected.

The problem is that when I compile it as C++ i get the same error message and
14882:1998 (and n3035) §6.5.3 says that

The for statement
      for ( for-init-statement conditionopt ; expressionopt ) statement
is equivalent to
      {
            for-init-statement
            while ( condition ) {
                   statement
                   expression ;
            }
      }

and then goes on to list some exceptions to this, none of which are of
importance here. Looking at §6.6.1 the only requirement on break statement is
that it shall occur in an /iteration-statement/ and that is, among other
things, a for statement, so as I read this the original code should be valid
C++ unless there are any undocumented restrictions on the ({ }) construct.

Are there any such restrictions or have I found a bug in the compiler?

/MF

Reply via email to