This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[C++ PATCH,committed] Fix PR14429
- From: Kriang Lerdsuwanakij <lerdsuwa at users dot sourceforge dot net>
- To: <gcc-patches at gcc dot gnu dot org>
- Date: Tue, 27 Jul 2004 22:52:56 +0700 (ICT)
- Subject: [C++ PATCH,committed] Fix PR14429
- Reply-to: <lerdsuwa at users dot sourceforge dot net>
Hi
This patch fixes the PR14429. There is a flaw inside the function
"coerce_template_template_parm". When checking its non-type parameter,
we should check whether its ARG is still dependent. If it is
dependent, no conclusion can be drawn until it is fully substituted.
Tested on i686-pc-linux-gnu. Commited to mainline as obvious.
--Kriang
2004-07-26 Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net>
PR c++/14429
* pt.c (coerce_template_template_parms) <PARM_DECL case>: Only check
when the type of ARG is not dependent.
2004-07-26 Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net>
PR c++/14429
* g++.dg/template/ttp11.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 Sat Jul 24 18:41:47 2004
--- gcc-main-new/gcc/cp/pt.c Sun Jul 25 01:08:29 2004
*************** coerce_template_template_parms (tree par
*** 3639,3649 ****
case PARM_DECL:
/* The tsubst call is used to handle cases such as
! template <class T, template <T> class TT> class D;
i.e. the parameter list of TT depends on earlier parameters. */
! if (!same_type_p
! (tsubst (TREE_TYPE (parm), outer_args, complain, in_decl),
! TREE_TYPE (arg)))
return 0;
break;
--- 3639,3654 ----
case PARM_DECL:
/* The tsubst call is used to handle cases such as
!
! template <int> class C {};
! template <class T, template <T> class TT> class D {};
! D<int, C> d;
!
i.e. the parameter list of TT depends on earlier parameters. */
! if (!dependent_type_p (TREE_TYPE (arg))
! && !same_type_p
! (tsubst (TREE_TYPE (parm), outer_args, complain, in_decl),
! TREE_TYPE (arg)))
return 0;
break;
diff -cprN gcc-main-save/gcc/testsuite/g++.dg/template/ttp11.C gcc-main-new/gcc/testsuite/g++.dg/template/ttp11.C
*** gcc-main-save/gcc/testsuite/g++.dg/template/ttp11.C Thu Jan 1 07:00:00 1970
--- gcc-main-new/gcc/testsuite/g++.dg/template/ttp11.C Sun Jul 25 01:09:06 2004
***************
*** 0 ****
--- 1,14 ----
+ // { dg-do compile }
+
+ // Origin: heinlein@informatik.uni-ulm.de
+
+ // PR c++/14429: Matching of template template parameter containing
+ // non-type parameter with type that depends on earlier parameter.
+
+ template <template <typename U, U* p> class T>
+ struct X {};
+
+ template <template <typename U, U* p> class T>
+ struct Y {
+ X<T> x;
+ };
diff -cprN gcc-main-save/gcc/testsuite/g++.dg/template/ttp12.C gcc-main-new/gcc/testsuite/g++.dg/template/ttp12.C
*** gcc-main-save/gcc/testsuite/g++.dg/template/ttp12.C Thu Jan 1 07:00:00 1970
--- gcc-main-new/gcc/testsuite/g++.dg/template/ttp12.C Sun Jul 25 01:13:38 2004
***************
*** 0 ****
--- 1,19 ----
+ // Copyright (C) 2004 Free Software Foundation
+ // Contributed by Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net>
+ // { dg-do compile }
+
+ // Check the type of non-type parameter in template template parameter
+ // only if it is dependent.
+
+ template <template <int* p> class T>
+ struct X {};
+
+ template <typename U, template <U* p> class T>
+ struct Y {
+ X<T> x;
+ };
+
+ template <int* p> struct Z {};
+
+ Y<int, Z> y1;
+ Y<char, Z> y2; // { dg-error "mismatch|expected|invalid" }