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

--- Comment #4 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-13 branch has been updated by Iain Buclaw
<[email protected]>:

https://gcc.gnu.org/g:8c9345901bad40284ab6382ad32691893412f87f

commit r13-10058-g8c9345901bad40284ab6382ad32691893412f87f
Author: Iain Buclaw <[email protected]>
Date:   Wed Jan 28 12:45:26 2026 +0100

    d: RVO/NRVO not done when returning a copy constructor

    RVO was already being done when returning a constructor call via a
    temporary, which in the front-end AST looks like:

        return S.this((__tmp = {}, &__tmp), args...);

    But this was not being done for copy construction calls, which instead
    looks like:

        return __copytmp = {}, S.this(&__copytmp, V(1).s), __copytmp;

    This pattern is now matched and the temporary gets set up as a
    DECL_VALUE_EXPR of the RESULT_DECL.

            PR d/123422

    gcc/d/ChangeLog:

            * expr.cc (ExprVisitor::visit (ArrayLiteralExp *)): Don't add
            TARGET_EXPR around constructor.
            * toir.cc (IRVisitor::visit (ReturnStatement *)): Recognize more
            patterns for return value optimization.

    gcc/testsuite/ChangeLog:

            * gdc.dg/torture/pr123422.d: New test.

    (cherry picked from commit 92f976fc2a87a867f70921b577f7c79acd214eaf)

Reply via email to