https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67302
--- Comment #4 from CVS Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Patrick Palka <ppa...@gcc.gnu.org>: https://gcc.gnu.org/g:21761d2b2b01f6cef4287c646845f6b3006546aa commit r12-1698-g21761d2b2b01f6cef4287c646845f6b3006546aa Author: Patrick Palka <ppa...@redhat.com> Date: Mon Jun 21 07:54:29 2021 -0400 c++: REF_PARENTHESIZED_P wrapper inhibiting NRVO [PR67302] Here, in C++14 or later, we remember the parentheses around 'a' in the return statement by using a REF_PARENTHESIZED_P wrapper, which ends up inhibiting NRVO because we don't look through this wrapper before checking the conditions for NRVO. This patch fixes this by calling maybe_undo_parenthesized_ref sooner in check_return_expr. PR c++/67302 gcc/cp/ChangeLog: * typeck.c (check_return_expr): Call maybe_undo_parenthesized_ref sooner, before the NRVO handling. gcc/testsuite/ChangeLog: * g++.dg/opt/nrv21.C: New test.