[Bug c++/125536] T[N] not substituted when N >= 2^31

"jakub at gcc dot gnu.org via Gcc-bugs" <[email protected]>
Newsgroups gmane.comp.gcc.bugs
Message-ID <[email protected]/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125536

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org

--- Comment #5 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
  /* If only one of the bounds used a MINUS_EXPR, compensate
     by adding one to the other bound.  */
  if (parm_cst && !arg_cst)
    parm_max = fold_build2_loc (input_location, PLUS_EXPR,
                                integer_type_node,
                                parm_max,
                                integer_one_node);
  else if (arg_cst && !parm_cst)
    arg_max = fold_build2_loc (input_location, PLUS_EXPR,
                               integer_type_node,
                               arg_max,
                               integer_one_node);
That probably should be using TREE_TYPE (parm_max) and build_int_cst (TREE_TYPE
(parm_max), 1) and similarly for arg_max...
--- gcc/cp/pt.cc.jj     2026-08-06 11:28:19.000000000 +0200
+++ gcc/cp/pt.cc        2026-08-06 23:08:20.780995510 +0200
@@ -26284,14 +26284,14 @@ unify_array_domain (tree tparms, tree ta
      by adding one to the other bound.  */
   if (parm_cst && !arg_cst)
     parm_max = fold_build2_loc (input_location, PLUS_EXPR,
-                               integer_type_node,
+                               TREE_TYPE (parm_max),
                                parm_max,
-                               integer_one_node);
+                               build_int_cst (TREE_TYPE (parm_max), 1));
   else if (arg_cst && !parm_cst)
     arg_max = fold_build2_loc (input_location, PLUS_EXPR,
-                              integer_type_node,
+                              TREE_TYPE (arg_max),
                               arg_max,
-                              integer_one_node);
+                              build_int_cst (TREE_TYPE (arg_max), 1));

   return unify (tparms, targs, parm_max, arg_max,
                UNIFY_ALLOW_INTEGER, explain_p);
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.