This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[C++ PATCH] Fix default arg processing of template template parm
- To: gcc-patches at gcc dot gnu dot org
- Subject: [C++ PATCH] Fix default arg processing of template template parm
- From: Kriang Lerdsuwanakij <lerdsuwa at users dot sourceforge dot net>
- Date: Fri, 12 Oct 2001 21:59:21 +0700
- Reply-To: lerdsuwa at users dot sourceforge dot net
Hi
The current GCC doesn't support the default argument processing behavior
of template template parameters. This is important when the template
template parameter is intended for standard containers such as
std::vector. To declare a class template taking std::vector as its
argument, we have to use the syntax
template<template<class T, class U = std::allocator<T> > class TT>
struct C {
TT<int> t; // Require default argument of U
};
C<std::vector> c;
The default argument of U that depends on other parameters (T in this case)
is not correctly expanded. The appended patch fixes this problem.
Bootstrapped and tested on i686-linux-gnu with no regressions.
Ok to install in the main trunk?
--Kriang
2001-10-12 Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net>
* pt.c (lookup_template_class): Build complete template arguments
for BOUND_TEMPLATE_TEMPLATE_PARM.
diff -cprN gcc-main-save3/gcc/cp/pt.c gcc-main-new/gcc/cp/pt.c
*** gcc-main-save3/gcc/cp/pt.c Sat Sep 22 22:46:23 2001
--- gcc-main-new/gcc/cp/pt.c Fri Oct 12 20:28:42 2001
*************** lookup_template_class (d1, arglist, in_d
*** 3918,3923 ****
--- 3918,3936 ----
parmlist = DECL_INNERMOST_TEMPLATE_PARMS (template);
+ /* Consider an example where a template template parameter declared as
+
+ template <class T, class U = std::allocator<T> > class TT
+
+ The template parameter level of T and U are one level larger than
+ of TT. To proper process the default argument of U, say when an
+ instantiation `TT<int>' is seen, we need to build the full
+ arguments containing {int} as the innermost level. Outer levels
+ can be obtained from `current_template_args ()'. */
+
+ if (processing_template_decl)
+ arglist = add_to_template_args (current_template_args (), arglist);
+
arglist2 = coerce_template_parms (parmlist, arglist, template,
complain, /*require_all_args=*/1);
if (arglist2 == error_mark_node)
diff -cprN gcc-main-save3/gcc/testsuite/g++.dg/template/ttp2.C gcc-main-new/gcc/testsuite/g++.dg/template/ttp2.C
*** gcc-main-save3/gcc/testsuite/g++.dg/template/ttp2.C Thu Jan 1 07:00:00 1970
--- gcc-main-new/gcc/testsuite/g++.dg/template/ttp2.C Thu Oct 11 22:26:42 2001
***************
*** 0 ****
--- 1,17 ----
+ // Copyright (C) 2001 Free Software Foundation
+ // Contributed by Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net>
+ // { dg-do compile }
+
+ template <class U> struct Alloc {};
+
+ template <class T, class U = Alloc<T> > struct Vector {};
+
+ template <template <class T, class U = Alloc<T> > class TT>
+ struct C {
+ TT<int> tt;
+ };
+
+ int main()
+ {
+ C<Vector> c;
+ }