This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: PR30891: poor diagnostic with namespace in the function scope
Manuel López-Ibáñez wrote:
>> 2007-03-12 Manuel Lopez-Ibanez <manu@gcc.gnu.org>
>>
>> PR c++/30891
>> * parser.c (cp_parser_statement): If 'namespace' is found, this only
>> can be a namespace alias definition, so parse it now.
>> (cp_parser_namespace_alias_definition): if we find an open brace
>> instead of '=', then this is actually a misplaced namespace
>> definition.
> Index: gcc/cp/parser.c
> ===================================================================
> --- gcc/cp/parser.c (revision 122755)
> +++ gcc/cp/parser.c (working copy)
> @@ -6305,6 +6305,16 @@ cp_parser_statement (cp_parser* parser,
> statement = cp_parser_try_block (parser);
> break;
>
> + case RID_NAMESPACE:
> + {
> + /* Try to parse the declaration-statement. */
> + cp_parser_declaration_statement (parser);
> + /* If that worked, we are done. */
> + if (!cp_parser_error_occurred (parser))
> + return;
> + goto restart;
> + }
Why the conditional return to restart? Why not just
cp_parser_declaration_statement, followed by return?
> @@ -10845,6 +10855,15 @@ cp_parser_namespace_alias_definition (cp
> if (identifier == error_mark_node)
> return;
> /* Look for the `=' token. */
> + if (cp_lexer_next_token_is (parser->lexer, CPP_OPEN_BRACE))
> + {
> + error ("%<namespace%> definition is not allowed here");
> + /* Skip the definition. */
> + cp_lexer_consume_token (parser->lexer);
> + cp_parser_skip_to_closing_brace (parser);
> + cp_lexer_consume_token (parser->lexer);
> + return;
> + }
This kind of change of recovery should always be done under the guard of:
if (!cp_parser_uncommitted_to_tentative_parse (parser))
since if this is a tentative parse, we want to abort the parse anyhow
because of the failure, so there's no point in skipping tokens, etc.
Thanks,
--
Mark Mitchell
CodeSourcery
mark@codesourcery.com
(650) 331-3385 x713