[patch] Fix PR c++/27315: ICE in do_decl_instantiation, at cp/pt.c
Volker Reichelt
reichelt@igpm.rwth-aachen.de
Tue May 9 21:42:00 GMT 2006
Currently we ICE on code like
struct A;
template void A::foo<0>();
PR27315.cc:2: error: invalid use of incomplete type 'struct A'
PR27315.cc:1: error: forward declaration of 'struct A'
PR27315.cc:2: internal compiler error: tree check: expected tree that contains 'decl common' structure, have 'error_mark' in do_decl_instantiation, at cp/pt.c:11220
Please submit a full bug report, [etc.]
Well, right at the beginning of do_decl_instantiation we have:
if (!decl)
/* An error occurred, for which grokdeclarator has already issued
an appropriate message. */
return;
But we don't check for decl being error_mark_node here, although
grokdeclarator also returns error_mark_node to indicate errors.
Consequently, we ICE later.
The patch below fixes this by also checking for error_mark_node.
Bootstrapped and regtested on x86_64-unknown-linux-gnu.
Ok for mainline, 4.1 branch, and 4.0 branch?
Regards,
Volker
:ADDPATCH C++:
2006-05-09 Volker Reichelt <reichelt@igpm.rwth-aachen.de>
PR c++/27315
* pt.c (do_decl_instantiation): Return early on invalid decl.
===================================================================
--- gcc/gcc/cp/pt.c (revision 113642)
+++ gcc/gcc/cp/pt.c (working copy)
@@ -11213,7 +11213,7 @@ do_decl_instantiation (tree decl, tree storage)
tree result = NULL_TREE;
int extern_p = 0;
- if (!decl)
+ if (!decl || decl == error_mark_node)
/* An error occurred, for which grokdeclarator has already issued
an appropriate message. */
return;
===================================================================
2006-05-09 Volker Reichelt <reichelt@igpm.rwth-aachen.de>
PR c++/27315
* g++.dg/template/operator6.C: New test.
* g++.dg/template/incomplete3.C: New test.
===================================================================
--- gcc/gcc/testsuite/g++.dg/template/operator6.C 2005-08-29 00:25:44 +0200
+++ gcc/gcc/testsuite/g++.dg/template/operator6.C 2006-05-09 16:13:42 +0200
@@ -0,0 +1,4 @@
+// PR c++/27315
+// { dg-do compile }
+
+template void operator+; // { dg-error "non-function" }
===================================================================
--- gcc/gcc/testsuite/g++.dg/template/incomplete3.C 2005-08-29 00:25:44 +0200
+++ gcc/gcc/testsuite/g++.dg/template/incomplete3.C 2006-05-09 16:23:19 +0200
@@ -0,0 +1,5 @@
+// PR c++/27315
+// { dg-do compile }
+
+struct A; // { dg-error "forward declaration" }
+template void A::foo<0>(); // { dg-error "before|incomplete" }
===================================================================
More information about the Gcc-patches
mailing list