This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Patch PR c++/42697
- From: Dodji Seketeli <dodji at redhat dot com>
- To: jason at redhat dot com
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Wed, 13 Jan 2010 20:27:05 +0100
- Subject: Patch PR c++/42697
Hello,
In tsubst_decl, during tsubsting of a FUNCTION_DECL that is a member of
a partially specialized class, we want to tsubst the complete set of
arguments that were used to specialize of the FUNCTION_DECL.
I believe we wrongly try to get the argument set from the most
general template instead of getting it from the specialized
FUNCTION_DECL itself, leading to an ICE later when we detect the
inconsistency between the arguments we are tsubsting and those we are
tsubsting into.
An exemple of FUNCTION_DECL (in the patch below) illustrating
that would be the definition
template<>
template<bool Option>
void fparser<int>::eval2(int r[2])
{
...
}
The patch below fixes that and was tested against trunk on
x86_unknown-linux-gnu.
This is not a regression so I think the fix is going to be staged
for 4.6.
Dodji
commit 0b65944c125203989d5766a14854ecc194895321
Author: Dodji Seketeli <dodji@redhat.com>
Date: Wed Jan 13 19:36:57 2010 +0100
Fix PR c++/42697
gcc/cp/ChangeLog:
PR c++/42697
*pt.c (tsubst_decl): Get the arguments of a specialization from
the specialization template, not from the most general template.
gcc/testsuite/ChangeLog:
PR c++/42697
* g++.dg/template/crash94.C: New test.
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index f27b931..0acb860 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -8825,7 +8825,8 @@ tsubst_decl (tree t, tree args, tsubst_flags_t complain)
specialize R. */
gen_tmpl = most_general_template (DECL_TI_TEMPLATE (t));
argvec = tsubst_template_args (DECL_TI_ARGS
- (DECL_TEMPLATE_RESULT (gen_tmpl)),
+ (DECL_TEMPLATE_RESULT
+ (DECL_TI_TEMPLATE (t))),
args, complain, in_decl);
/* Check to see if we already have this specialization. */
diff --git a/gcc/testsuite/g++.dg/template/crash94.C b/gcc/testsuite/g++.dg/template/crash94.C
new file mode 100644
index 0000000..810aed0
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/crash94.C
@@ -0,0 +1,28 @@
+// Origin: PR c++/42697
+// { dg-do compile }
+
+template<class Value_t>
+class fparser
+{
+ template<bool Option>
+ void eval2(Value_t r[2]);
+public:
+ void evaltest();
+};
+
+template<>
+template<bool Option>
+void fparser<int>::eval2(int r[2])
+{
+ struct ObjType {};
+}
+
+
+template<class Value_t>
+void fparser<Value_t>::evaltest
+ ()
+{
+ eval2<false>(0);
+}
+
+template class fparser<int>;