This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[C++ PATCH for 3.3/trunk] Fix PR10956 (Function template specializationtsubst regression)
- From: Kriang Lerdsuwanakij <lerdsuwa at users dot sourceforge dot net>
- To: <gcc-patches at gcc dot gnu dot org>
- Date: Thu, 29 May 2003 22:08:19 +0700 (ICT)
- Subject: [C++ PATCH for 3.3/trunk] Fix PR10956 (Function template specializationtsubst regression)
- Reply-to: <lerdsuwa at users dot sourceforge dot net>
Hi
This patch fixes PR10956 which is a regression in 3.3 and trunk.
The problem appears we are tsubst'ing the body of function templates
where its enclosing is specialized. The full set of template arguments
(which is required to locate the right specialization) should not be
used here. GCC currently fail to notice this and cause ICE deep
inside tsubst.
Patch tested on i686-pc-linux-gnu. OK for trunk and 3.3 branch?
--Kriang
2003-05-29 Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net>
PR c++/10956
* pt.c (instantiate_decl): Don't use full template arguments if
we are dealing with specializations.
2003-05-29 Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net>
PR c++/10956
* g++.dg/template/spec9.C: New test.
diff -cprN gcc-33-save/gcc/cp/pt.c gcc-33-new/gcc/cp/pt.c
*** gcc-33-save/gcc/cp/pt.c Fri May 23 21:36:25 2003
--- gcc-33-new/gcc/cp/pt.c Wed May 28 23:16:36 2003
*************** instantiate_decl (d, defer_ok)
*** 10252,10261 ****
code_pattern = DECL_TEMPLATE_RESULT (td);
! if (DECL_NAMESPACE_SCOPE_P (d) && !DECL_INITIALIZED_IN_CLASS_P (d))
/* In the case of a friend template whose definition is provided
outside the class, we may have too many arguments. Drop the
! ones we don't need. */
args = get_innermost_template_args
(gen_args, TMPL_PARMS_DEPTH (DECL_TEMPLATE_PARMS (td)));
else
--- 10252,10262 ----
code_pattern = DECL_TEMPLATE_RESULT (td);
! if ((DECL_NAMESPACE_SCOPE_P (d) && !DECL_INITIALIZED_IN_CLASS_P (d))
! || DECL_TEMPLATE_SPECIALIZATION (td))
/* In the case of a friend template whose definition is provided
outside the class, we may have too many arguments. Drop the
! ones we don't need. The same is true for specializations. */
args = get_innermost_template_args
(gen_args, TMPL_PARMS_DEPTH (DECL_TEMPLATE_PARMS (td)));
else
diff -cprN gcc-33-save/gcc/testsuite/g++.dg/template/spec9.C gcc-33-new/gcc/testsuite/g++.dg/template/spec9.C
*** gcc-33-save/gcc/testsuite/g++.dg/template/spec9.C Thu Jan 1 07:00:00 1970
--- gcc-33-new/gcc/testsuite/g++.dg/template/spec9.C Wed May 28 23:19:38 2003
***************
*** 0 ****
--- 1,21 ----
+ // { dg-do compile }
+
+ // Origin: Lynn Akers <lakers@peachtree.com>
+ // Wolfgang Bangerth <bangerth@ticam.utexas.edu>
+
+ // PR c++/10956: Incorrect template substitution for member template
+ // specialization inside template class.
+
+ template <int> struct C {
+ template<typename T> void pre_add(T);
+ };
+
+ template<>
+ template<typename T>
+ void C<32>::pre_add(T) {
+ T pre;
+ }
+
+ int main() {
+ C<32>().pre_add<int>(1);
+ }