[Bug d/123422] d: RVO/NRVO not done when returning a copy constructor by __rvalue
cvs-commit at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Wed Jan 28 16:18:25 GMT 2026
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123422
--- Comment #3 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-14 branch has been updated by Iain Buclaw
<ibuclaw@gcc.gnu.org>:
https://gcc.gnu.org/g:0ea3b54254510b56e3b043ad5e3c14656ae7514a
commit r14-12273-g0ea3b54254510b56e3b043ad5e3c14656ae7514a
Author: Iain Buclaw <ibuclaw@gdcproject.org>
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)
More information about the Gcc-bugs
mailing list