Hi! The following patch on top of https://gcc.gnu.org/pipermail/gcc-patches/2025-January/673177.html (in review currently) https://gcc.gnu.org/pipermail/gcc-patches/2024-December/672055.html (acked but waiting for the former) https://gcc.gnu.org/pipermail/gcc-patches/2025-January/672438.html https://gcc.gnu.org/pipermail/gcc-patches/2025-January/672496.html (waiting for review) uses the new function introduced in the second patch to fix up unify deduction of array sizes.
Ok for trunk? 2025-01-10 Jakub Jelinek <ja...@redhat.com> PR c++/118390 * cp-tree.h (count_ctor_elements): Declare. * call.cc (count_ctor_elements): No longer static. * pt.cc (unify): Use count_ctor_elements instead of CONSTRUCTOR_NELTS. * g++.dg/cpp/embed-20.C: New test. * g++.dg/cpp0x/pr118390.C: New test. --- gcc/cp/cp-tree.h.jj 2025-01-10 11:47:58.478841366 +0100 +++ gcc/cp/cp-tree.h 2025-01-10 12:40:51.898875583 +0100 @@ -6815,6 +6815,7 @@ extern tree type_decays_to (tree); extern tree extract_call_expr (tree); extern tree build_trivial_dtor_call (tree, bool = false); extern tristate ref_conv_binds_to_temporary (tree, tree, bool = false); +extern unsigned HOST_WIDE_INT count_ctor_elements (tree); extern tree build_user_type_conversion (tree, tree, int, tsubst_flags_t); extern tree build_new_function_call (tree, vec<tree, va_gc> **, --- gcc/cp/call.cc.jj 2025-01-10 11:49:42.155399433 +0100 +++ gcc/cp/call.cc 2025-01-10 12:40:12.906413343 +0100 @@ -4333,7 +4333,7 @@ has_non_trivial_temporaries (tree expr) /* Return number of initialized elements in CTOR. */ -static unsigned HOST_WIDE_INT +unsigned HOST_WIDE_INT count_ctor_elements (tree ctor) { unsigned HOST_WIDE_INT len = 0; --- gcc/cp/pt.cc.jj 2025-01-10 10:32:28.801729684 +0100 +++ gcc/cp/pt.cc 2025-01-10 12:41:19.801491043 +0100 @@ -25064,7 +25064,7 @@ unify (tree tparms, tree targs, tree par && deducible_array_bound (TYPE_DOMAIN (parm))) { /* Also deduce from the length of the initializer list. */ - tree max = size_int (CONSTRUCTOR_NELTS (arg)); + tree max = size_int (count_ctor_elements (arg)); tree idx = compute_array_index_type (NULL_TREE, max, tf_none); if (idx == error_mark_node) return unify_invalid (explain_p); --- gcc/testsuite/g++.dg/cpp/embed-20.C.jj 2025-01-10 12:30:08.578762083 +0100 +++ gcc/testsuite/g++.dg/cpp/embed-20.C 2025-01-10 12:29:29.882296675 +0100 @@ -0,0 +1,14 @@ +// PR c++/118390 +// { dg-do compile { target c++11 } } +// { dg-options "" } + +template<typename T, int N> +constexpr int +foo (const T (&x)[N]) +{ + return N; +} + +static_assert (foo ({ + #embed __FILE__ limit (64) +}) == 64, ""); --- gcc/testsuite/g++.dg/cpp0x/pr118390.C.jj 2025-01-10 12:30:59.748055186 +0100 +++ gcc/testsuite/g++.dg/cpp0x/pr118390.C 2025-01-10 12:31:34.681572583 +0100 @@ -0,0 +1,23 @@ +// PR c++/118390 +// { dg-do compile { target c++11 } } +// { dg-options "" } + +template<typename T, int N> +constexpr int +foo (const T (&x)[N]) +{ + return N; +} + +static_assert (foo ({ + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, +}) == 160, ""); Jakub