https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123422
--- Comment #1 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Iain Buclaw <[email protected]>: https://gcc.gnu.org/g:92f976fc2a87a867f70921b577f7c79acd214eaf commit r16-7118-g92f976fc2a87a867f70921b577f7c79acd214eaf 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.
