Range-based for in c++98

Jason Merrill jason@redhat.com
Mon Oct 4 13:47:00 GMT 2010


On 10/02/2010 01:50 PM, Rodrigo Rivas wrote:
>> I would change cp_parser_range_for to use cp_parser_decl_specifier_seq
>> > instead of cp_parser_type_specifier_seq and then wait to complain about
>> > defining a type until after we've seen the ':'.
> I already tried that, but it didn't work. It seemed to me that it was
> because it called cp_parser_commit_to_tentative_parse(), and if then I
> wanted to roll-back the parsing of the range-for, I went badly. I had
> to agree with Manuel that the tentative parsing is a bit messy...

Ah, yes.  So we should share the parsing of the decl-specifier-seq with 
the C-style for loop, which allows us to avoid the tentative parsing.

> Admittedly, this is not a "trailing_return_type", but AFAICT it has
> exactly the same restrictions.

The restrictions are slightly different; in the case of a trailing 
return type a class-specifier is not one of the expansions, so we don't 
treat a { as beginning a class body.  In the case of a 
type-specifier-seq, we do treat it as beginning a class body, but we 
give an error about it.

Jason



More information about the Gcc mailing list