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

--- Comment #1 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Jason Merrill <[email protected]>:

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

commit r17-1147-gbfecb8bf5de888710a79ffff31370f48d511f18c
Author: Joe Natter <[email protected]>
Date:   Thu May 21 20:20:16 2026 +0200

    c++: Fix spurious -Wduplicated-branches for new (nothrow) T[n] [PR125422]

    When allocating an array of a trivial type with new (nothrow),
    build_new_1() may emit a compiler-generated COND_EXPR of the form

      (alloc_node != nullptr) ? rval : alloc_node

    For trivial arrays without constructors, destructors, or array cookies,
    rval remains equal to data_addr and is therefore equivalent to
    alloc_node.  This causes both branches of the generated COND_EXPR to be
    identical, triggering -Wduplicated-branches on user code.

    Avoid building the null-check COND_EXPR when rval == data_addr.

    gcc/cp/ChangeLog:
            PR c++/125422
            * init.cc (build_new_1): Avoid building a null-check
            COND_EXPR when rval == data_addr.

    gcc/testsuite/ChangeLog:
            PR c++/125422
            * g++.dg/warn/Wduplicated-branches10.C: New test.

    Signed-off-by: Joe Natter <[email protected]>
    Reviewed-by: Jason Merrill <[email protected]>

Reply via email to