This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
C++ PATCH: PR 28058
- From: Mark Mitchell <mark at codesourcery dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Sun, 27 Aug 2006 10:57:41 -0700
- Subject: C++ PATCH: PR 28058
- Reply-to: mark at codesourcery dot com
This patch fixes PR c++/28058, an ICE-on-invalid regression. The C++
standard forbids declaring an explicit specialization for a function
after that specialization has already been used. We failed to enforce
this rule for constructors and destructors due to the "cloned
functions" that we use to implement multiple entry points for
constructors/destructors in C++; that problem is easily solved by
setting TREE_USED for the original function when setting it for the
clone.
Tested on x86_64-unknown-linux-gnu, applied on the mainline and on the
4.1 branch.
--
Mark Mitchell
CodeSourcery
mark@codesourcery.com
(650) 331-3385 x713
2006-08-27 Mark Mitchell <mark@codesourcery.com>
PR c++/28058
* pt.c (register_specialization): Return error_mark_node for
specialization-after-instantiation.
* decl2.c (mark_used): Mark the main function used when one of its
clones is used.
2006-08-27 Mark Mitchell <mark@codesourcery.com>
PR c++/28058
* g++.dg/template/spec31.C: New test.
Index: gcc/cp/pt.c
===================================================================
--- gcc/cp/pt.c (revision 116469)
+++ gcc/cp/pt.c (working copy)
@@ -1164,7 +1164,7 @@ register_specialization (tree spec, tree
{
error ("specialization of %qD after instantiation",
fn);
- return spec;
+ return error_mark_node;
}
else
{
Index: gcc/cp/decl2.c
===================================================================
--- gcc/cp/decl2.c (revision 116469)
+++ gcc/cp/decl2.c (working copy)
@@ -3494,6 +3494,8 @@ mark_used (tree decl)
}
TREE_USED (decl) = 1;
+ if (DECL_CLONED_FUNCTION_P (decl))
+ TREE_USED (DECL_CLONED_FUNCTION (decl)) = 1;
/* If we don't need a value, then we don't need to synthesize DECL. */
if (skip_evaluation)
return;
Index: gcc/testsuite/g++.dg/template/spec31.C
===================================================================
--- gcc/testsuite/g++.dg/template/spec31.C (revision 0)
+++ gcc/testsuite/g++.dg/template/spec31.C (revision 0)
@@ -0,0 +1,10 @@
+// PR c++/28058
+
+template<int> struct A
+{
+ A() {}
+};
+
+A<0> a;
+
+template<> A<0>::A() {} // { dg-error "specialization" }