This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[C++ PATCH] [PR13474] Fold value-dependent array domain in time for type deduction


This is a little followup to Nathan's work on array domain folding in
templates. The testcase shows that a value-dependent domain was not always
folded in time for deduction. This was due to an old piece of code in tsubst
which was trying to check whether we're ready to fold the domain or not after a
substitution. The code is completely obsoleted by the recent work in
compute_array_index_type, thus removing it actually fixes the bug.

I tried to carefully follow all code paths to make sure we don't affect the ABI
with this change. I'm pretty confident that the ABI does not change because the
logic within compute_array_index_type is pretty much the same, and it still
constructs a MINUS_EXPR (but in the right way) when processing_template_decl
and abi=1.

Who said that we all love when we can fix bugs by simply removing code? :)

Tested on i686-pc-linux-gnu with no new regressions. OK for mainline?

Giovanni Bajo

2004-01-11  Giovanni Bajo  <>

        PR c++/13474
        * pt.c (tsubst): Now that compute_array_index_type is smart enough to
        do the right thing, after we tsubst into an array domain, we do not
        need anymore additional (broken) logic to handle cases where we
        still need to keep the domain unfolded.

2004-01-11  Giovanni Bajo  <>

        PR c++/13474
        * g++.dg/template/array3.C: New test.

Index: pt.c
RCS file: /cvs/gcc/gcc/gcc/cp/pt.c,v
retrieving revision 1.808
diff -c -3 -p -r1.808 pt.c
*** pt.c        25 Dec 2003 16:28:50 -0000      1.808
--- pt.c        11 Jan 2004 02:55:26 -0000
*************** tsubst (tree t, tree args, tsubst_flags_
*** 6577,6599 ****
        if (!processing_template_decl)
          max = decl_constant_value (max);

-       if (processing_template_decl
-           /* When providing explicit arguments to a template
-              function, but leaving some arguments for subsequent
-              deduction, MAX may be template-dependent even if we're
-              not PROCESSING_TEMPLATE_DECL.  We still need to check for
-              template parms, though; MAX won't be an INTEGER_CST for
-              dynamic arrays, either.  */
-           || (TREE_CODE (max) != INTEGER_CST
-               && uses_template_parms (max)))
-         {
-           tree itype = make_node (INTEGER_TYPE);
-           TYPE_MIN_VALUE (itype) = size_zero_node;
-           TYPE_MAX_VALUE (itype) = build_min (MINUS_EXPR, sizetype, max,
-                                               integer_one_node);
-           return itype;
-         }
        if (integer_zerop (omax))
            /* Still allow an explicit array of size zero.  */
--- 6577,6582 ----

// { dg-do compile }
// Origin: Graeme Prentice <gprentice at paradise dot net dot nz>
// PR c++/13474: An array domain which is value-dependent must be folded
//  in time for deduction.

template< int X, int Y, int (*array_ptr)[Y] >
class A;

int array[5];

template< int X >
class A<X,5,&array> {};

int main()
  A<6,5,&array> z1;

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]