This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[patch] Fix PR c++/28710: ICE redeclaring template as non-template
- From: Volker Reichelt <reichelt at igpm dot rwth-aachen dot de>
- To: gcc-patches at gcc dot gnu dot org
- Date: Mon, 14 Aug 2006 23:42:52 +0200 (CEST)
- Subject: [patch] Fix PR c++/28710: ICE redeclaring template as non-template
The C++-frontend stumbles over the following invalid code snippet since
GCC 4.0.1:
template<int> union A;
struct A;
bug.cc:2: error: redeclaration of 'A<<anonymous> >' as a non-template
bug.cc:2: internal compiler error: tree check: expected class 'type', have 'exceptional' (error_mark) in xref_tag, at cp/decl.c:9703
Please submit a full bug report, [etc.]
The problem is the following code from xref_tag:
error ("redeclaration of %qT as a non-template", t);
t = error_mark_node;
After correctly diagnosing the error, the compiler assigns error_mark_node
to t (which is returned later) to indicate failure. The problem is that
the code between this point and the return cannot handle error_mark_nodes.
One way to fix this is to check for error_mark_nodes in more places.
However, I chose to return the error_mark_node directly (which is also
done a couple of lines above).
I also improved the error message a little by adding the position of
the conflicting declaration.
Bootstrapped and regtested on x86_64-unknown-linux-gnu.
Ok for mainline, 4.1 branch, and 4.0 branch?
Regards,
Volker
:ADDPATCH C++:
2006-08-14 Volker Reichelt <reichelt@igpm.rwth-aachen.de>
PR c++/28710
* decl.c (xref_tag): Improve error message. Return early on error.
===================================================================
--- gcc/gcc/cp/decl.c 2006-08-14 11:10:08 +0200
+++ gcc/gcc/cp/decl.c 2006-08-14 11:05:24 +0200
@@ -9662,7 +9662,8 @@ xref_tag (enum tag_types tag_code, tree
&& CLASSTYPE_IS_TEMPLATE (t))
{
error ("redeclaration of %qT as a non-template", t);
- t = error_mark_node;
+ error ("previous declaration %q+D", t);
+ POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, error_mark_node);
}
/* Make injected friend class visible. */
===================================================================
2006-08-14 Volker Reichelt <reichelt@igpm.rwth-aachen.de>
PR c++/28710
* g++.dg/template/redecl4.C: New test.
===================================================================
--- gcc/gcc/testsuite/g++.dg/template/redecl4.C 2003-09-23 19:59:22 +0200
+++ gcc/gcc/testsuite/g++.dg/template/redecl4.C 2006-08-14 11:21:58 +0200
@@ -0,0 +1,5 @@
+// PR c++/28710
+// { dg-do compile }
+
+template<int> union A; // { dg-error "previous" }
+struct A; // { dg-error "non-template" }
===================================================================