]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++ __integer_pack conversion again [PR111357]
authorJason Merrill <jason@redhat.com>
Thu, 21 Sep 2023 14:39:46 +0000 (15:39 +0100)
committerJason Merrill <jason@redhat.com>
Fri, 22 Sep 2023 13:23:26 +0000 (14:23 +0100)
As Jakub pointed out, the real problem here is that in a partial
substitution we're forgetting the conversion to the type of the non-type
template argument, because maybe_convert_nontype_argument doesn't do
anything with value-dependent arguments.  I'm experimenting with changing
that, but in the meantime we can work around it here.

PR c++/111357

gcc/cp/ChangeLog:

* pt.cc (expand_integer_pack): Use IMPLICIT_CONV_EXPR.

gcc/cp/pt.cc

index ea5379098a5d73637cdd948b0b65801c587c4007..73ac1cb597cd12653920f6a882491881a05d462a 100644 (file)
@@ -3769,6 +3769,13 @@ expand_integer_pack (tree call, tree args, tsubst_flags_t complain,
     {
       if (hi != ohi)
        {
+         /* Work around maybe_convert_nontype_argument not doing this for
+            dependent arguments.  Don't use IMPLICIT_CONV_EXPR_NONTYPE_ARG
+            because that will make tsubst_copy_and_build ignore it.  */
+         tree type = tsubst (TREE_TYPE (ohi), args, complain, in_decl);
+         if (!TREE_TYPE (hi) || !same_type_p (type, TREE_TYPE (hi)))
+           hi = build1 (IMPLICIT_CONV_EXPR, type, hi);
+
          call = copy_node (call);
          CALL_EXPR_ARG (call, 0) = hi;
        }
@@ -3779,8 +3786,6 @@ expand_integer_pack (tree call, tree args, tsubst_flags_t complain,
     }
   else
     {
-      hi = perform_implicit_conversion_flags (integer_type_node, hi, complain,
-                                             LOOKUP_IMPLICIT);
       hi = instantiate_non_dependent_expr (hi, complain);
       hi = cxx_constant_value (hi, complain);
       int len = valid_constant_size_p (hi) ? tree_to_shwi (hi) : -1;