re PR c++/30891 (poor diagnostic with namespace in the function scope)

2007-03-15  Manuel Lopez-Ibanez  <manu@gcc.gnu.org>

	PR c++/30891
cp/
	* 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.
testsuite/
	* g++.dg/parse/namespace-definition.C: New.

From-SVN: r122962
parent 9b439fe1
2007-03-15 Manuel Lopez-Ibanez <manu@gcc.gnu.org> 2007-03-15 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.
2007-03-15 Manuel Lopez-Ibanez <manu@gcc.gnu.org>
PR c++/24924 PR c++/24924
* decl.c (cxx_init_decl_processing): Move command-line options * decl.c (cxx_init_decl_processing): Move command-line options
processing to c-opts.c. processing to c-opts.c.
......
...@@ -6373,6 +6373,11 @@ cp_parser_statement (cp_parser* parser, tree in_statement_expr, ...@@ -6373,6 +6373,11 @@ cp_parser_statement (cp_parser* parser, tree in_statement_expr,
statement = cp_parser_try_block (parser); statement = cp_parser_try_block (parser);
break; break;
case RID_NAMESPACE:
/* This must be a namespace alias definition. */
cp_parser_declaration_statement (parser);
return;
default: default:
/* It might be a keyword like `int' that can start a /* It might be a keyword like `int' that can start a
declaration-statement. */ declaration-statement. */
...@@ -11040,6 +11045,16 @@ cp_parser_namespace_alias_definition (cp_parser* parser) ...@@ -11040,6 +11045,16 @@ cp_parser_namespace_alias_definition (cp_parser* parser)
if (identifier == error_mark_node) if (identifier == error_mark_node)
return; return;
/* Look for the `=' token. */ /* Look for the `=' token. */
if (!cp_parser_uncommitted_to_tentative_parse_p (parser)
&& 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;
}
cp_parser_require (parser, CPP_EQ, "`='"); cp_parser_require (parser, CPP_EQ, "`='");
/* Look for the qualified-namespace-specifier. */ /* Look for the qualified-namespace-specifier. */
namespace_specifier namespace_specifier
......
2007-03-15 Manuel Lopez-Ibanez <manu@gcc.gnu.org> 2007-03-15 Manuel Lopez-Ibanez <manu@gcc.gnu.org>
PR c++/30891
* g++.dg/parse/namespace-definition.C: New.
2007-03-15 Manuel Lopez-Ibanez <manu@gcc.gnu.org>
PR c++/24924 PR c++/24924
* g++.dg/cpp/pedantic-errors.C: New. * g++.dg/cpp/pedantic-errors.C: New.
* g++.dg/cpp/permissive.C: New. * g++.dg/cpp/permissive.C: New.
// PR 30891
// { dg-do compile }
int main() {
int i = 0;
namespace foo { // { dg-error "'namespace' definition is not allowed here" }
int j = 0;
}
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment