On Wed, Nov 19, 2025 at 09:28:42AM +0100, Daniele Sahebi wrote:
> Fixed what was asked.
> Bootstrapped and regtested on x86_64-linux-unknown-gnu, please tell me
> if there are any other issues.
>
> ---
> Currently, build_over_call calls build_cplus_new in template decls, generating
> a TARGET_EXPR that it then passes to fold_non_dependent_expr, which ends up
> calling tsubst_expr, and since tsubst_expr doesn't handle TARGET_EXPRs, it
> ICEs.
>
> Since there is no way for this code path to be executed without causing an
> ICE, I believe it can be removed.
>
> PR c++/122658
>
> gcc/cp/ChangeLog:
>
> * call.cc (build_over_call): Remove if block that ICEs.
>
> gcc/testsuite/ChangeLog:
>
> * g++.dg/pr122658.C: New test.
>
> Co-authored-by: Jakub Jelinek <[email protected]>
> ---
> gcc/cp/call.cc | 13 +++----------
> gcc/testsuite/g++.dg/pr122658.C | 15 +++++++++++++++
> 2 files changed, 18 insertions(+), 10 deletions(-)
> create mode 100644 gcc/testsuite/g++.dg/pr122658.C
>
> diff --git a/gcc/cp/call.cc b/gcc/cp/call.cc
> index f80d597b3394..7985c2d5e1bb 100644
> --- a/gcc/cp/call.cc
> +++ b/gcc/cp/call.cc
> @@ -10328,18 +10328,11 @@ build_over_call (struct z_candidate *cand, int
> flags, tsubst_flags_t complain)
> TREE_NO_WARNING (expr) = true;
> if (immediate_invocation_p (fn))
> {
> - tree obj_arg = NULL_TREE, exprimm = expr;
> + tree obj_arg = NULL_TREE;
> if (DECL_CONSTRUCTOR_P (fn))
> obj_arg = first_arg;
> - if (obj_arg
> - && is_dummy_object (obj_arg)
> - && !type_dependent_expression_p (obj_arg))
> - {
> - exprimm = build_cplus_new (DECL_CONTEXT (fn), expr, complain);
> - obj_arg = NULL_TREE;
> - }
> /* Look through *(const T *)&obj. */
> - else if (obj_arg && INDIRECT_REF_P (obj_arg))
> + if (obj_arg && INDIRECT_REF_P (obj_arg))
> {
> tree addr = TREE_OPERAND (obj_arg, 0);
> STRIP_NOPS (addr);
> @@ -10351,7 +10344,7 @@ build_over_call (struct z_candidate *cand, int flags,
> tsubst_flags_t complain)
> obj_arg = TREE_OPERAND (addr, 0);
> }
> }
> - fold_non_dependent_expr (exprimm, complain,
> + fold_non_dependent_expr (expr, complain,
> /*manifestly_const_eval=*/true,
> obj_arg);
> }
> diff --git a/gcc/testsuite/g++.dg/pr122658.C b/gcc/testsuite/g++.dg/pr122658.C
> new file mode 100644
> index 000000000000..22b9d3e664ab
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/pr122658.C
> @@ -0,0 +1,15 @@
> +/* PR c++/53055 */
Well I just noticed this is wrong.
I was looking around the other tests to see what they were doing and
that must have slipped in then...
Do I send another patch in this case?
> +/* { dg-do compile } */
> +/* { dg-options "-std=c++20" } */
> +
> +struct S {
> + consteval S () noexcept { }
> + consteval S (const S &) = default;
> +};
> +
> +template <typename T>
> +void
> +foo ()
> +{
> + constexpr auto s = S();
> +}
> --
> 2.47.3
>