https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120453
Iain Sandoe <iains at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |jason at gcc dot gnu.org --- Comment #9 from Iain Sandoe <iains at gcc dot gnu.org> --- OK so the reason this fails is because check_return_expr() concludes that we cannot do NRVO and we try to do the bad conversion. There are two reasons that it makes this conclusion. 1. We actually need a "DECL_RAMP_P()" - that is easy to fix (i have a fix). #define DECL_RAMP_P(NODE) \ DECL_COROUTINE_P (NODE) && !DECL_RAMP_FN (NODE) 2. named_return_value_okay_p is false because want_nrvo_p() is false because aggregate_value_p () is false because TYPE_EMPTY_P() is true for the return type. Now ISTM that we can elide the conversion in the case that TYPE_EMPTY_P() == true (assuming that can_do_nrvo_p() would be true otherwise). so... updating the condition to: if (DECL_RAMP_P (current_function_decl) && (named_return_value_okay_p || (can_do_nrvo_p (bare_retval, functype) && TYPE_EMPTY_P (functype)))) converted = true; @jason - does this seem reasonable, or are there yet other cases we should cater for?