re PR c++/9212 (Internal compiler error in grokdeclarator, at cp/decl.c:11052 [gcc...
authorNathan Sidwell <nathan@codesourcery.com>
Thu, 16 Jan 2003 17:08:54 +0000 (17:08 +0000)
committerNathan Sidwell <nathan@gcc.gnu.org>
Thu, 16 Jan 2003 17:08:54 +0000 (17:08 +0000)
cp:
PR C++/9212
* parser.c (cp_parser_direct_declarator): If accepting either
abstract or named, the name must be an unqualified-id.
testsuite:
* g++.dg/parse/ambig2.C: New test.

From-SVN: r61399

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

index 826d7366593253c860a97d35d81de04f69a29f74..39b294dc3f8b77e6a00a476557dc38fdc8d315a7 100644 (file)
@@ -1,3 +1,9 @@
+2003-01-16  Nathan Sidwell  <nathan@codesourcery.com>
+
+       PR c++/9212
+       * parser.c (cp_parser_direct_declarator): If accepting either
+       abstract or named, the name must be an unqualified-id.
+
 2003-01-16  Kaveh R. Ghazi  <ghazi@caip.rutgers.edu>
 
        * class.c (layout_virtual_bases): Avoid signed/unsigned warning.
index 68997ad170b26d7059fab5131d4df4af8794ecd9..07b35a28fb53ee0b8d7f3fd40416438bf7cff09b 100644 (file)
@@ -1150,7 +1150,7 @@ typedef enum cp_parser_declarator_kind
   CP_PARSER_DECLARATOR_ABSTRACT,
   /* We want a named declarator.  */
   CP_PARSER_DECLARATOR_NAMED,
-  /* We don't mind.  */
+  /* We don't mind, but the name must be an unqualified-id  */
   CP_PARSER_DECLARATOR_EITHER
 } cp_parser_declarator_kind;
 
@@ -10168,16 +10168,24 @@ cp_parser_direct_declarator (parser, dcl_kind, ctor_dtor_or_conv_p)
          if (dcl_kind == CP_PARSER_DECLARATOR_EITHER)
            cp_parser_parse_tentatively (parser);
          declarator = cp_parser_declarator_id (parser);
-         if (dcl_kind == CP_PARSER_DECLARATOR_EITHER
-             && !cp_parser_parse_definitely (parser))
-           declarator = error_mark_node;
+         if (dcl_kind == CP_PARSER_DECLARATOR_EITHER)
+           {
+             if (!cp_parser_parse_definitely (parser))
+               declarator = error_mark_node;
+             else if (TREE_CODE (declarator) != IDENTIFIER_NODE)
+               {
+                 cp_parser_error (parser, "expected unqualified-id");
+                 declarator = error_mark_node;
+               }
+           }
+         
          if (declarator == error_mark_node)
            break;
          
          if (TREE_CODE (declarator) == SCOPE_REF)
            {
              tree scope = TREE_OPERAND (declarator, 0);
-         
+
              /* In the declaration of a member of a template class
                 outside of the class itself, the SCOPE will sometimes
                 be a TYPENAME_TYPE.  For example, given:
index 4beef4fad6df5c41701fb8eb3c3820e3d7c71fc1..f40783f0488eb92ab7f202c286a9dfc260ea8df7 100644 (file)
@@ -1,3 +1,7 @@
+2003-01-16  Nathan Sidwell  <nathan@codesourcery.com>
+
+       * g++.dg/parse/ambig2.C: New test.
+
 2003-01-15  Richard Henderson  <rth@redhat.com>
 
        * g++.dg/tls/init-2.C: Update error message string.
diff --git a/gcc/testsuite/g++.dg/parse/ambig2.C b/gcc/testsuite/g++.dg/parse/ambig2.C
new file mode 100644 (file)
index 0000000..7b000c6
--- /dev/null
@@ -0,0 +1,27 @@
+// { dg-do compile }
+
+// Copyright (C) 2003 Free Software Foundation, Inc.
+// Contributed by Nathan Sidwell 6 Jan 2003 <nathan@codesourcery.com>
+
+// PR 9212. We erroneously accepted an ill-formed
+// function-declaration, rather than a variable initializer.
+
+
+struct A
+{
+    enum E { e };
+    A(E);
+};
+
+struct B
+{
+    enum F { f };
+    B(F);
+};
+
+struct C
+{
+    C(A, B, A);
+};
+
+C c(A(A::e), B(B::f), A(A::e)); // This is not a function declaration