On Fri, 2010-03-05 at 15:07 -0800, Joe Buck wrote: > 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.
I think that is problematic stance - at the moment the documentation quite explicitly allows one to jump out of a statement expression. What is needed is an added paragraph (or bullet or whatever) on some page describing standard deviations or extensions, something like In C++ the /for-init-statement/, /condition/ and /expression/ part of an /iteration-statement/ are not treated as part of the /iteration-statement/. The effect of this is that statement expressions containing either of break or continue in statement expressions appearing outside of the /statement/ in a /iteration-statement/ are regarded as being outside of the /iteration-statement/. /MF