[C++ PATCH] Fix PR10552
Kriang Lerdsuwanakij
lerdsuwa@users.sourceforge.net
Thu May 1 13:36:00 GMT 2003
Hi
This patch fixes a latent bug during template template argument
substitution. Normally, we don't have to process any TEMPLATE_DECL
that appears as template template argument. However, we need to
deal with one special case, i.e., when it is an unqualified name
that is a member class template nested inside a template class.
This is described in detail in the comment within the patch.
Tested on i686-pc-linux-gnu. OK to commit to main trunk?
--Kriang
2003-05-01 Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net>
PR c++/10552
* pt.c (tsubst_copy): Handle TEMPLATE_DECL that is a member class
template and has dependent context.
2003-05-01 Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net>
PR c++/10552
* g++.dg/template/ttp6.C: New test.
diff -cprN gcc-main-save/gcc/cp/pt.c gcc-main-new/gcc/cp/pt.c
*** gcc-main-save/gcc/cp/pt.c Tue Apr 29 21:11:06 2003
--- gcc-main-new/gcc/cp/pt.c Thu May 1 20:22:13 2003
*************** tsubst_copy (t, args, complain, in_decl)
*** 7287,7293 ****
--- 7289,7317 ----
args, complain, in_decl);
else if (is_member_template (t))
return tsubst (t, args, complain, in_decl);
+ else if (DECL_CLASS_SCOPE_P (t)
+ && uses_template_parms (DECL_CONTEXT (t)))
+ {
+ /* Template template argument like the following example need
+ special treatment:
+
+ template <template <class> class TT> struct C {};
+ template <class T> struct D {
+ template <class U> struct E {};
+ C<E> c; // #1
+ };
+ D<int> d; // #2
+
+ We are processing the template argument `E' in #1 for
+ the template instantiation #2. Originally, `E' is a
+ TEMPLATE_DECL with `D<T>' as its DECL_CONTEXT. Now we
+ have to substitute this with one having context `D<int>'. */
+
+ tree context = tsubst (DECL_CONTEXT (t), args, complain, in_decl);
+ return lookup_field (context, DECL_NAME(t), 0, false);
+ }
else
+ /* Ordinary template template argument. */
return t;
case LOOKUP_EXPR:
diff -cprN gcc-main-save/gcc/testsuite/g++.dg/template/ttp6.C gcc-main-new/gcc/testsuite/g++.dg/template/ttp6.C
*** gcc-main-save/gcc/testsuite/g++.dg/template/ttp6.C Thu Jan 1 07:00:00 1970
--- gcc-main-new/gcc/testsuite/g++.dg/template/ttp6.C Thu May 1 20:28:46 2003
***************
*** 0 ****
--- 1,21 ----
+ // { dg-do compile }
+
+ // Origin: Eelis van der Weegan <gccbugs@contacts.eelis.net>
+
+ // PR c++/10552: Member class template as template template argument
+ // substitution issue.
+
+ template <template <typename> class A, typename>
+ struct B
+ {
+ typedef typename A<int>::t t;
+ };
+
+ template <typename D>
+ struct E
+ {
+ template <typename> struct F { typedef int t; };
+ typedef typename B<F, D>::t t;
+ };
+
+ typedef E<int>::t t;
More information about the Gcc-patches
mailing list