]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c++/30891 (poor diagnostic with namespace in the function scope)
authorManuel López-Ibáñez <manu@gcc.gnu.org>
Thu, 15 Mar 2007 22:45:17 +0000 (22:45 +0000)
committerManuel López-Ibáñez <manu@gcc.gnu.org>
Thu, 15 Mar 2007 22:45:17 +0000 (22:45 +0000)
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

gcc/cp/ChangeLog
gcc/cp/parser.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/parse/namespace-definition.C [new file with mode: 0644]

index f48aa6bd091f2f9dfa501ef8b7cd70faaf38a07d..730c59e9af99128c4090bc2d3157a103bc7f65d2 100644 (file)
@@ -1,3 +1,12 @@
+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
index 54c7668a50d7efce920c5e62980d19361b593155..e1230471a625b88cb9c29ebe2f58e1a5774b900d 100644 (file)
@@ -6373,6 +6373,11 @@ cp_parser_statement (cp_parser* parser, tree in_statement_expr,
          statement = cp_parser_try_block (parser);
          break;
 
+       case RID_NAMESPACE:
+         /* This must be a namespace alias definition.  */
+         cp_parser_declaration_statement (parser);
+         return;
+         
        default:
          /* It might be a keyword like `int' that can start a
             declaration-statement.  */
@@ -11040,6 +11045,16 @@ cp_parser_namespace_alias_definition (cp_parser* parser)
   if (identifier == error_mark_node)
     return;
   /* 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, "`='");
   /* Look for the qualified-namespace-specifier.  */
   namespace_specifier
index 3a043c1c21aa2e07feaee8fee4b7e9bf08d6268d..b56294f0df68534fbfcb515beea869401a9dfa96 100644 (file)
@@ -1,3 +1,8 @@
+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
diff --git a/gcc/testsuite/g++.dg/parse/namespace-definition.C b/gcc/testsuite/g++.dg/parse/namespace-definition.C
new file mode 100644 (file)
index 0000000..b7d4034
--- /dev/null
@@ -0,0 +1,10 @@
+// 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;
+}