This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[c++ patch] Fix bug 35
- From: Nathan Sidwell <nathan at codesourcery dot com>
- To: gcc-patches at gcc dot gnu dot org
- Cc: mark at codesourcery dot com
- Date: Sat, 29 Dec 2001 12:10:14 +0000
- Subject: [c++ patch] Fix bug 35
- Organization: Codesourcery LLC
Hi,
this fixes bug 35. PARM_DECLS are used for non-type template parms,
and when tsubsting those we were default promoting them, which is
wrong. This patch marks template PARM_DECLs as such, and then
does not promote them.
built & tested on i686-pc-linux-gnu, ok?
nathan
--
Dr Nathan Sidwell :: http://www.codesourcery.com :: CodeSourcery LLC
'But that's a lie.' - 'Yes it is. What's your point?'
nathan@codesourcery.com : http://www.cs.bris.ac.uk/~nathan/ : nathan@acm.org
2001-12-28 Nathan Sidwell <nathan@codesourcery.com>
PR c++/35
* cp-tree.h (DECL_LANG_FLAG_0): Used for PARM_DECL too.
(DECL_TEMPLATE_PARM_P): A PARM_DECL might be one too.
* pt.c (process_template_parm): SET_DECL_TEMPLATE_PARM_P on the
PARM_DECL.
(tsubst_template_parms): Break up loop statements.
(tsubst_decl, case PARM_DECL): Copy DECL_TEMPLATE_PARM_P. Template
parm PARM_DECLs don't get promoted.
Index: cp/cp-tree.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/cp-tree.h,v
retrieving revision 1.667
diff -c -3 -p -r1.667 cp-tree.h
*** cp-tree.h 2001/12/18 03:35:25 1.667
--- cp-tree.h 2001/12/29 10:33:44
*************** Boston, MA 02111-1307, USA. */
*** 87,93 ****
Usage of DECL_LANG_FLAG_?:
0: DECL_ERROR_REPORTED (in VAR_DECL).
! DECL_TEMPLATE_PARM_P (in CONST_DECL, TYPE_DECL, or TEMPLATE_DECL)
DECL_LOCAL_FUNCTION_P (in FUNCTION_DECL)
DECL_MUTABLE_P (in FIELD_DECL)
1: C_TYPEDEF_EXPLICITLY_SIGNED (in TYPE_DECL).
--- 87,93 ----
Usage of DECL_LANG_FLAG_?:
0: DECL_ERROR_REPORTED (in VAR_DECL).
! DECL_TEMPLATE_PARM_P (in PARM_DECL, CONST_DECL, TYPE_DECL, or TEMPLATE_DECL)
DECL_LOCAL_FUNCTION_P (in FUNCTION_DECL)
DECL_MUTABLE_P (in FIELD_DECL)
1: C_TYPEDEF_EXPLICITLY_SIGNED (in TYPE_DECL).
*************** enum ptrmemfunc_vbit_where_t
*** 2719,2724 ****
--- 2719,2725 ----
#define DECL_TEMPLATE_PARM_P(NODE) \
(DECL_LANG_FLAG_0 (NODE) \
&& (TREE_CODE (NODE) == CONST_DECL \
+ || TREE_CODE (NODE) == PARM_DECL \
|| TREE_CODE (NODE) == TYPE_DECL \
|| TREE_CODE (NODE) == TEMPLATE_DECL))
Index: cp/pt.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/pt.c,v
retrieving revision 1.566
diff -c -3 -p -r1.566 pt.c
*** pt.c 2001/12/18 14:13:44 1.566
--- pt.c 2001/12/29 10:35:26
*************** process_template_parm (list, next)
*** 1935,1940 ****
--- 1935,1941 ----
/* is a const-param */
parm = grokdeclarator (TREE_VALUE (parm), TREE_PURPOSE (parm),
PARM, 0, NULL);
+ SET_DECL_TEMPLATE_PARM_P (parm);
/* [temp.param]
*************** tsubst_template_parms (parms, args, comp
*** 5405,5421 ****
for (i = 0; i < TREE_VEC_LENGTH (new_vec); ++i)
{
! tree default_value =
! TREE_PURPOSE (TREE_VEC_ELT (TREE_VALUE (parms), i));
! tree parm_decl =
! TREE_VALUE (TREE_VEC_ELT (TREE_VALUE (parms), i));
!
! TREE_VEC_ELT (new_vec, i)
! = build_tree_list (maybe_fold_nontype_arg (
! tsubst_expr (default_value, args, complain,
! NULL_TREE)),
! tsubst (parm_decl, args, complain,
! NULL_TREE));
}
*new_parms =
--- 5406,5421 ----
for (i = 0; i < TREE_VEC_LENGTH (new_vec); ++i)
{
! tree tuple = TREE_VEC_ELT (TREE_VALUE (parms), i);
! tree default_value = TREE_PURPOSE (tuple);
! tree parm_decl = TREE_VALUE (tuple);
!
! parm_decl = tsubst (parm_decl, args, complain, NULL_TREE);
! default_value = tsubst_expr (default_value, args,
! complain, NULL_TREE);
! tuple = build_tree_list (maybe_fold_nontype_arg (default_value),
! parm_decl);
! TREE_VEC_ELT (new_vec, i) = tuple;
}
*new_parms =
*************** tsubst_decl (t, args, type)
*** 5905,5910 ****
--- 5905,5913 ----
case PARM_DECL:
{
r = copy_node (t);
+ if (DECL_TEMPLATE_PARM_P (t))
+ SET_DECL_TEMPLATE_PARM_P (r);
+
TREE_TYPE (r) = type;
c_apply_type_quals_to_decl (cp_type_quals (type), r);
*************** tsubst_decl (t, args, type)
*** 5915,5921 ****
/*complain=*/1, in_decl);
DECL_CONTEXT (r) = NULL_TREE;
! if (PROMOTE_PROTOTYPES
&& INTEGRAL_TYPE_P (type)
&& TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node))
DECL_ARG_TYPE (r) = integer_type_node;
--- 5918,5924 ----
/*complain=*/1, in_decl);
DECL_CONTEXT (r) = NULL_TREE;
! if (!DECL_TEMPLATE_PARM_P (r) && PROMOTE_PROTOTYPES
&& INTEGRAL_TYPE_P (type)
&& TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node))
DECL_ARG_TYPE (r) = integer_type_node;
// { dg-do compile }
// Copyright (C) 2001 Free Software Foundation, Inc.
// Contributed by Nathan Sidwell 26 Dec 2001 <nathan@nathan@codesourcery.com>
// PR 35. We were default promoting template PARM_DECLs
template <short B> class R {};
template <class T> class A
{
public:
template <short B>
void operator() (R<B> const &);
};
int main() {
A<int> a;
R<1> r;
a (r);
return 0;
}