This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
(C++) patch to array bounds handling
- To: egcs-patches at cygnus dot com
- Subject: (C++) patch to array bounds handling
- From: Jason Merrill <jason at cygnus dot com>
- Date: Sat, 21 Nov 1998 05:40:28 -0800
1998-11-21 Jason Merrill <jason@yorick.cygnus.com>
* decl.c (grokdeclarator): Allow a boolean constant for array
bounds, odd as that sounds.
* pt.c (unify): Be more strict about non-type parms, except for
array bounds.
(UNIFY_ALLOW_INTEGER): New macro.
Index: decl.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/decl.c,v
retrieving revision 1.265
diff -c -p -r1.265 decl.c
*** decl.c 1998/11/19 02:35:09 1.265
--- decl.c 1998/11/21 13:31:50
*************** grokdeclarator (declarator, declspecs, d
*** 9692,9698 ****
}
if (TREE_CODE (TREE_TYPE (size)) != INTEGER_TYPE
! && TREE_CODE (TREE_TYPE (size)) != ENUMERAL_TYPE)
{
cp_error ("size of array `%D' has non-integer type",
dname);
--- 9692,9699 ----
}
if (TREE_CODE (TREE_TYPE (size)) != INTEGER_TYPE
! && TREE_CODE (TREE_TYPE (size)) != ENUMERAL_TYPE
! && TREE_CODE (TREE_TYPE (size)) != BOOLEAN_TYPE)
{
cp_error ("size of array `%D' has non-integer type",
dname);
Index: pt.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/pt.c,v
retrieving revision 1.238
diff -c -p -r1.238 pt.c
*** pt.c 1998/11/19 02:35:13 1.238
--- pt.c 1998/11/21 13:31:54
*************** static tree saved_trees;
*** 75,80 ****
--- 75,81 ----
#define UNIFY_ALLOW_MORE_CV_QUAL 1
#define UNIFY_ALLOW_LESS_CV_QUAL 2
#define UNIFY_ALLOW_DERIVED 4
+ #define UNIFY_ALLOW_INTEGER 8
static int unify PROTO((tree, tree, tree, tree, int, int*));
static int resolve_overloaded_unification PROTO((tree, tree, tree, tree,
*************** check_cv_quals_for_unify (strict, arg, p
*** 7304,7310 ****
UNIFY_ALLOW_DERIVED:
Allow the deduced ARG to be a template base class of ARG,
or a pointer to a template base class of the type pointed to by
! ARG. */
int
unify (tparms, targs, parm, arg, strict, explicit_mask)
--- 7305,7314 ----
UNIFY_ALLOW_DERIVED:
Allow the deduced ARG to be a template base class of ARG,
or a pointer to a template base class of the type pointed to by
! ARG.
! UNIFY_ALLOW_INTEGER:
! Allow any integral type to be deduced. See the TEMPLATE_PARM_INDEX
! case for more information. */
int
unify (tparms, targs, parm, arg, strict, explicit_mask)
*************** unify (tparms, targs, parm, arg, strict,
*** 7487,7492 ****
--- 7491,7512 ----
my_friendly_abort (42);
}
+ /* [temp.deduct.type] If, in the declaration of a function template
+ with a non-type template-parameter, the non-type
+ template-parameter is used in an expression in the function
+ parameter-list and, if the corresponding template-argument is
+ deduced, the template-argument type shall match the type of the
+ template-parameter exactly, except that a template-argument
+ deduced from an array bound may be of any integral type. */
+ if (same_type_p (TREE_TYPE (arg), TREE_TYPE (parm)))
+ /* OK */;
+ else if ((strict & UNIFY_ALLOW_INTEGER)
+ && (TREE_CODE (TREE_TYPE (parm)) == INTEGER_TYPE
+ || TREE_CODE (TREE_TYPE (parm)) == BOOLEAN_TYPE))
+ /* OK */;
+ else
+ return 1;
+
TREE_VEC_ELT (targs, idx) = copy_to_permanent (arg);
return 0;
*************** unify (tparms, targs, parm, arg, strict,
*** 7560,7570 ****
{
if (TYPE_MIN_VALUE (parm) && TYPE_MIN_VALUE (arg)
&& unify (tparms, targs, TYPE_MIN_VALUE (parm),
! TYPE_MIN_VALUE (arg), UNIFY_ALLOW_NONE, explicit_mask))
return 1;
if (TYPE_MAX_VALUE (parm) && TYPE_MAX_VALUE (arg)
&& unify (tparms, targs, TYPE_MAX_VALUE (parm),
! TYPE_MAX_VALUE (arg), UNIFY_ALLOW_NONE, explicit_mask))
return 1;
}
/* We use the TYPE_MAIN_VARIANT since we have already
--- 7580,7592 ----
{
if (TYPE_MIN_VALUE (parm) && TYPE_MIN_VALUE (arg)
&& unify (tparms, targs, TYPE_MIN_VALUE (parm),
! TYPE_MIN_VALUE (arg), UNIFY_ALLOW_INTEGER,
! explicit_mask))
return 1;
if (TYPE_MAX_VALUE (parm) && TYPE_MAX_VALUE (arg)
&& unify (tparms, targs, TYPE_MAX_VALUE (parm),
! TYPE_MAX_VALUE (arg), UNIFY_ALLOW_INTEGER,
! explicit_mask))
return 1;
}
/* We use the TYPE_MAIN_VARIANT since we have already
*************** unify (tparms, targs, parm, arg, strict,
*** 7695,7702 ****
integer_type_node,
arg, t2));
! return unify (tparms, targs, t1, t, UNIFY_ALLOW_NONE,
! explicit_mask);
}
/* else fall through */
--- 7717,7723 ----
integer_type_node,
arg, t2));
! return unify (tparms, targs, t1, t, strict, explicit_mask);
}
/* else fall through */