This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: break in statement expression in while condition fails to compile
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Prathamesh Kulkarni <bilbotheelffriend at gmail dot com>
- Cc: Florian Weimer <fweimer at redhat dot com>, gcc at gcc dot gnu dot org
- Date: Wed, 11 Dec 2013 14:50:54 +0100
- Subject: Re: break in statement expression in while condition fails to compile
- Authentication-results: sourceware.org; auth=none
- References: <CAJXstsCRcHALsqELKtB3aKn01Jq5GQuBxcdrMcHTcEjdaGq=sA at mail dot gmail dot com> <52A74566 dot 9000002 at redhat dot com> <CAJXstsDzO36Sn1rPKrmLAHEUhD8pzdBnM=j-PZxBhYPDf4UCsA at mail dot gmail dot com>
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
On Wed, Dec 11, 2013 at 07:13:47PM +0530, Prathamesh Kulkarni wrote:
> >From the bug-report (comment 4):
> 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.
>
> So I guess g++ should compile it ?
> g++ rejects it too:
> foo.cpp:3:14: error: break statement not within loop or switch
> while ( ({ break; 0; }) )
Statement expressions are GCC extensions and without that extension,
you can't put a break or continue anywhere in a loop but in the loop
body, so the exact wording of the standard isn't that important, for
standard conforming C and C++ that wording nuances make no difference, what
matters is how we define the extension and (ideally) document it if it isn't
documented yet. Similarly what exactly clang implements here isn't that
important, as they just implemented the GCC extension, either correctly, or
not.
Jakub