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

Re: The scope of a for statement


On Fri, Mar 05, 2010 at 02:40:44PM -0800, Magnus Fromreide wrote:
> On Fri, Mar 05, 2010 at 12:06:01PM -0800, Joe Buck wrote:
> > On Fri, Mar 05, 2010 at 11:38:23AM -0800, Magnus Fromreide wrote:
> > > Hello.
> > > 
> > > I tried to do
> > > 
> > > for (;; ({ break; }))
> > > 	printf("Hello\n");
> > > 
> > > and got an error message:

...

> > Ideally a GNU extension should be specified as well as the rest of the
> > standard is specified, but I'm not surprised that this doesn't work.
> 
> So you would say this points to a buglet in the specification of statement
> expressions?
> 
> Or is it a bug in the C++ implementation, but one that is unimportant as it
> is impossible to detect using standard C++?

Either way, it's low priority, but if you care, I think that the "fix"
might just be to document that certain uses don't work, and to warn the
user that he/she isn't going to get a very good diagnostic if such uses
are tried.

If I were required to come up with a "fix", I would specify that it's not
valid to break out of the statement expression (with a break, continue, or
goto) and thus forbid ({ break;}), not just here but everywhere.  Throwing
exceptions would be OK because ordinary expression evaluation can throw
exceptions.


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