This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
C++ PATCH: PR 20208
- From: Mark Mitchell <mark at codesourcery dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Wed, 9 Mar 2005 10:51:59 -0800
- Subject: C++ PATCH: PR 20208
- Reply-to: mark at codesourcery dot com
This patch fixes PR c++/20208, a bug in which we forgot that, after
substituting into the types of PARM_DECLs for template functions, we
then have to apply the function-to-pointer and array-to-pointer
conversions.
--
Mark Mitchell
CodeSourcery, LLC
mark@codesourcery.com
2005-03-09 Mark Mitchell <mark@codesourcery.com>
PR c++/20208
* pt.c (tsubst_decl): Apply array-to-pointer and
function-to-pointer conversions to function arguments.
(regenerate_decl_from_template): Likewise.
2005-03-09 Mark Mitchell <mark@codesourcery.com>
PR c++/20208
* g++.dg/template/array13.C: New test.
Index: cp/pt.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/pt.c,v
retrieving revision 1.979
diff -c -5 -p -r1.979 pt.c
*** cp/pt.c 5 Mar 2005 15:44:20 -0000 1.979
--- cp/pt.c 9 Mar 2005 18:32:51 -0000
*************** tsubst_decl (tree t, tree args, tsubst_f
*** 6466,6475 ****
--- 6466,6476 ----
r = copy_node (t);
if (DECL_TEMPLATE_PARM_P (t))
SET_DECL_TEMPLATE_PARM_P (r);
type = tsubst (TREE_TYPE (t), args, complain, in_decl);
+ type = type_decays_to (type);
TREE_TYPE (r) = type;
cp_apply_type_quals_to_decl (cp_type_quals (type), r);
if (DECL_INITIAL (r))
{
*************** regenerate_decl_from_template (tree decl
*** 11087,11096 ****
--- 11088,11098 ----
if (DECL_NAME (decl_parm) != DECL_NAME (pattern_parm))
DECL_NAME (decl_parm) = DECL_NAME (pattern_parm);
parm_type = tsubst (TREE_TYPE (pattern_parm), args, tf_error,
NULL_TREE);
+ parm_type = type_decays_to (parm_type);
if (!same_type_p (TREE_TYPE (decl_parm), parm_type))
TREE_TYPE (decl_parm) = parm_type;
decl_parm = TREE_CHAIN (decl_parm);
pattern_parm = TREE_CHAIN (pattern_parm);
}
Index: testsuite/g++.dg/template/array13.C
===================================================================
RCS file: testsuite/g++.dg/template/array13.C
diff -N testsuite/g++.dg/template/array13.C
*** /dev/null 1 Jan 1970 00:00:00 -0000
--- testsuite/g++.dg/template/array13.C 9 Mar 2005 18:32:51 -0000
***************
*** 0 ****
--- 1,14 ----
+ // PR c++/20208
+ // { dg-do run }
+ // { dg-options "-O2" }
+
+ extern "C" void abort();
+
+ template <typename T>
+ inline void *Foo (T arg) { return &arg[0]; }
+
+ int main () {
+ int bry[2];
+ if (Foo<int[2]>(bry) != bry)
+ abort();
+ }