This is the mail archive of the gcc-bugs@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]

[Bug c/44715] Break in increment expression of "for" statement inconsistent with g++



------- Comment #2 from pinskia at gmail dot com  2010-06-29 16:40 -------
Subject: Re:   New: Break in increment expression of "for" statement
inconsistent with g++

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)?
If it is valid, what does each standard say about the break there? If  
they say the same thing then I say both frontends should behave the  
same but if the c standard says a break should apply to the outer one  
then we should follow that for statement expressions also.

On Jun 29, 2010, at 9:20 AM, "doug dot gregor at gmail dot com"
<gcc-bugzilla@gcc.gnu.org 
 > wrote:

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


-- 


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


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