re PR c++/18782 (ICE on invalid pointer-to-member declaration)
authorNathan Sidwell <nathan@codesourcery.com>
Fri, 3 Dec 2004 10:51:13 +0000 (10:51 +0000)
committerNathan Sidwell <nathan@gcc.gnu.org>
Fri, 3 Dec 2004 10:51:13 +0000 (10:51 +0000)
cp:
PR c++/18782
* decl.c (grokdeclarator): Make sure class in pointer to member is
not a namespace.
testsuite:
PR c++/18782
* g++.dg/parse/ptrmem2.C: New.

From-SVN: r91681

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

index 5ac6cd74b0756f098ea2a568252235eef0ec0c6a..7ce41e4c9d5c29c00f1055f234f93e326842676a 100644 (file)
@@ -1,3 +1,9 @@
+2004-12-03  Nathan Sidwell  <nathan@codesourcery.com>
+
+       PR c++/18782
+       * decl.c (grokdeclarator): Make sure class in pointer to member is
+       not a namespace.
+
 2004-12-02  Nathan Sidwell  <nathan@codesourcery.com>
 
        PR c++/18318
index 92f294f0884dfd060593802a677fee3546a42221..bf7b80fbd84ad9ed348dad03adb50c73fd6dca6e 100644 (file)
@@ -7430,8 +7430,19 @@ grokdeclarator (const cp_declarator *declarator,
          else if (TREE_CODE (type) == METHOD_TYPE)
            type = build_ptrmemfunc_type (build_pointer_type (type));
          else if (declarator->kind == cdk_ptrmem)
-           type = build_ptrmem_type (declarator->u.pointer.class_type,
-                                     type);
+           {
+             /* We might have parsed a namespace as the class type.  */
+             if (TREE_CODE (declarator->u.pointer.class_type)
+                 == NAMESPACE_DECL)
+               {
+                 error ("%qD is a namespace",
+                        declarator->u.pointer.class_type);
+                 type = build_pointer_type (type);
+               }
+             else
+               type = build_ptrmem_type (declarator->u.pointer.class_type,
+                                         type);
+           }
          else
            type = build_pointer_type (type);
 
index a24a39e359a230d316b502c059e41cbfe36512f4..7f6dc120bd0262a8811b93d87b1a80d5d981524b 100644 (file)
@@ -1,5 +1,8 @@
 2004-12-03  Nathan Sidwell  <nathan@codesourcery.com>
 
+       PR c++/18782
+       * g++.dg/parse/ptrmem2.C: New.
+
        PR c++/18318
        * g++.dg/template/new1.C: New.
 
diff --git a/gcc/testsuite/g++.dg/parse/ptrmem2.C b/gcc/testsuite/g++.dg/parse/ptrmem2.C
new file mode 100644 (file)
index 0000000..bbc116e
--- /dev/null
@@ -0,0 +1,11 @@
+// { dg-do compile }
+
+// Copyright (C) 2004 Free Software Foundation, Inc.
+// Contributed by Nathan Sidwell 2 Dec 2004 <nathan@codesourcery.com>
+
+// PR 18782: ICE with ptr-to-member
+// Origin:   Volker Reichelt <reichelt@gcc.gnu.org>
+
+namespace A {}
+
+int A::* p; // { dg-error "is a namespace" "" }