public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: Andrew Pinski <pinskia@gmail.com>
To: "gcc-bugzilla@gcc.gnu.org" <gcc-bugzilla@gcc.gnu.org>
Cc: "gcc-bugs@gcc.gnu.org" <gcc-bugs@gcc.gnu.org>
Subject: Re: [Bug c/44715]  New: Break in increment expression of "for" statement inconsistent with g++
Date: Tue, 29 Jun 2010 16:40:00 -0000	[thread overview]
Message-ID: <DB7F85B0-5BEE-4034-9DE2-873E70B0B4BE@gmail.com> (raw)
In-Reply-To: <bug-44715-10727@http.gcc.gnu.org/bugzilla/>

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
>


  parent reply	other threads:[~2010-06-29 16:40 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-06-29 16:20 doug dot gregor at gmail dot com
2010-06-29 16:36 ` [Bug c/44715] " joseph at codesourcery dot com
2010-06-29 16:40 ` Andrew Pinski [this message]
2010-06-29 16:40 ` pinskia at gmail dot com
2010-06-29 16:47 ` joseph at codesourcery dot com
2010-07-06  5:28 ` ecyrbe at gmail dot com

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=DB7F85B0-5BEE-4034-9DE2-873E70B0B4BE@gmail.com \
    --to=pinskia@gmail.com \
    --cc=gcc-bugs@gcc.gnu.org \
    --cc=gcc-bugzilla@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).