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

--- Comment #22 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-14 branch has been updated by Jason Merrill
<ja...@gcc.gnu.org>:

https://gcc.gnu.org/g:b4f66a79e0c9b65d78aed6c982bdcff48ed098d5

commit r14-11347-gb4f66a79e0c9b65d78aed6c982bdcff48ed098d5
Author: Jason Merrill <ja...@redhat.com>
Date:   Mon Jan 27 18:30:18 2025 -0500

    c++: init-list opt and lvalue initializers [PR118673]

    When fn returns {extension}, the ArrayRef in the initializer_list is
    constructed to point to 'extension', the variable with static storage
    duration.  The optimization was copying extension's value into a temporary
    array and constructing the ArrayRef to point to that temporary copy
instead,
    resulting in a dangling pointer.  So suppress this optimization if the
    element constructor takes a reference and the initializer is a
non-mergeable
    lvalue.

            PR c++/118673

    gcc/cp/ChangeLog:

            * call.cc (maybe_init_list_as_array): Check for lvalue
            initializers.
            * cp-tree.h (enum cp_lvalue_kind_flags): Add clk_mergeable.
            * tree.cc (lvalue_kind): Return it.
            (non_mergeable_glvalue_p): New.
            (test_lvalue_kind): Adjust.

    gcc/testsuite/ChangeLog:

            * g++.dg/cpp0x/initlist-opt6.C: New test.

Reply via email to