[PATCH] Fix ICE in C++ grokdeclarator (PR c++/21495)
Jakub Jelinek
jakub@redhat.com
Wed May 11 10:51:00 GMT 2005
Hi!
GCC 4.0+ ICEs on the (invalid) testcase below when trying to issue
error about that.
declarator->declarator->u.id.unqualified_name is NULL, so we get a segfault.
declarator here is cdk_reference, declarator->declarator cdk_function
and declarator->declarator->declarator cdk_id.
Now, reading grokdeclarator it seems to me that it previously already
found the right declarator node with the identifier (id_declarator)
and already computed name as well
(if (is_typename_at_global_scope (tmp)) name = IDENTIFIER_POINTER (tmp)
else name = "<invalid operator>"; is done earlier as well for IDENTIFIERs).
Tested with make all-target-libstdc++-v3; make check-g++,
ok for 4.0/HEAD if it passes a full bootstrap/regression testing?
2005-05-11 Jakub Jelinek <jakub@redhat.com>
PR c++/21495
* decl.c (grokdeclarator): For "storage class specified for"
warning, use id_declarator instead of declarator and don't set name.
* g++.dg/parse/extern1.C: New test.
--- gcc/cp/decl.c.jj 2005-05-11 11:50:14.000000000 +0200
+++ gcc/cp/decl.c 2005-05-11 11:50:14.000000000 +0200
@@ -6965,24 +6965,12 @@ grokdeclarator (const cp_declarator *dec
{
if (decl_context == FIELD)
{
- tree tmp = NULL_TREE;
int op = 0;
if (declarator)
{
- /* Avoid trying to get an operand off an identifier node. */
- if (declarator->kind != cdk_id)
- tmp = declarator->declarator->u.id.unqualified_name;
- else
- tmp = declarator->u.id.unqualified_name;
+ tree tmp = id_declarator->u.id.unqualified_name;
op = IDENTIFIER_OPNAME_P (tmp);
- if (IDENTIFIER_TYPENAME_P (tmp))
- {
- if (is_typename_at_global_scope (tmp))
- name = IDENTIFIER_POINTER (tmp);
- else
- name = "<invalid operator>";
- }
}
error ("storage class specified for %s %qs",
op ? "member operator" : "field",
--- gcc/testsuite/g++.dg/parse/extern1.C.jj 2005-05-11 12:42:16.000000000 +0200
+++ gcc/testsuite/g++.dg/parse/extern1.C 2005-05-11 12:42:27.000000000 +0200
@@ -0,0 +1,14 @@
+// PR c++/21495
+// { dg-do compile }
+
+class A
+{
+ extern void *copy (void) // { dg-error "storage class specified for field" }
+ {
+ return 0;
+ }
+ extern A &operator= (const A &) // { dg-error "storage class specified for member operator" }
+ {
+ return *this;
+ }
+};
Jakub
More information about the Gcc-patches
mailing list