https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114619

--- Comment #5 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Simon Martin <simar...@gcc.gnu.org>:

https://gcc.gnu.org/g:887bdabfe3e315d661bed55800cd4f64542c7029

commit r15-7348-g887bdabfe3e315d661bed55800cd4f64542c7029
Author: Simon Martin <si...@nasilyan.com>
Date:   Tue Feb 4 10:44:10 2025 +0100

    c++: Properly detect calls to digest_init in build_vec_init [PR114619]

    We currently ICE in checking mode with cxx_dialect < 17 on the following
    valid code

    === cut here ===
    struct X {
      X(const X&) {}
    };
    extern X x;
    void foo () {
      new X[1]{x};
    }
    === cut here ===

    We trip on a gcc_checking_assert in cp_gimplify_expr due to a
    TARGET_EXPR that is not TARGET_EXPR_ELIDING_P. As pointed by Jason, the
    problem is that build_vec_init does not recognize that digest_init has
    been called, and we end up calling the copy constructor twice.

    This happens because the detection in build_vec_init assumes that BASE
    is a reference to the array, while it's a pointer to its first element
    here. This patch makes sure that the detection works in both cases.

            PR c++/114619

    gcc/cp/ChangeLog:

            * init.cc (build_vec_init): Properly determine whether
            digest_init has been called.

    gcc/testsuite/ChangeLog:

            * g++.dg/init/no-elide4.C: New test.

Reply via email to