On 20 September 2010 20:19, Rodrigo <rodrigorivasco...@gmail.com> wrote:
>> Well, yes, this is true but there is still the issue that
>>
>> void f() {
>> for(class C{};;)
>>   ;
>> }
>>
>> generates the message
>>
>> error: types may not be defined in range-based for loops
>>
>> when compiled with -std=c++0x and no patches and that is odd since this
>> loop isn't range-based.
> Oh, I see...
> The problem is that regular C for loops allows defining types in the
> first statement, whereas range-based for loops do not. That, if I'm
> reading the draft correctly.
>
> So the problem is that when setting the
> type_definition_forbidden_message to non-NULL, when it sees the type it
> calls error() instead of cp_parser_error() so the
> cp_parser_parse_tentatively has no effect.
>
> The easy solution would be to remove the assignment to
> type_definition_forbidden_message and then check for this case
> particulary.

cp_parser_type_specifier_seq could return some indication of why the
parsing has failed or whether it has parsed a declaration. This is
much more useful than just throwing an error. In general this is true
of the whole C++ parser.

> Or we can change the cp_parser_check_type_definition() function to call
> cp_parser_error() instead of error().

No please, cp_parser_error() is almost always annoying and
uninformative saying things like:

expected __asm__ before ';'

because it lacks context.

> Or we can just accept the type definition in the range-for and hope that
> nobody will notice :P

You will have to diagnose it with -pedantic anyway.

>
> Regards.
> Rodrigo
>
>

Reply via email to