The following program exhibits different behavior with gcc vs. g++:

dgregor$ cat t.c
#include <stdio.h>

int main()
{
  int i;
  for( i = 0; i < 3; )
    for( ; ; ({ i++; break; }) )
      printf( "%d\n", i );
}

With gcc, the break in the statement expression applies to the outer "for"
loop, so we get just "0" as output:

dgregor$ gcc t.c && ./a.out
0

with g++, the break in the statement expression applies to the inner "for"
loop, so we get "0" "1" and "2" as the output:

dgregor$ g++ t.c && ./a.out
0
1
2

g++ seems to have the right behavior here, and in any case g++ can't really be
changed now: Qt's foreach macro depends on having "break" bind to the inner for
loop.


-- 
           Summary: Break in increment expression of "for" statement
                    inconsistent with g++
           Product: gcc
           Version: 4.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: doug dot gregor at gmail dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44715

Reply via email to