-
Notifications
You must be signed in to change notification settings - Fork 1
Description
Spawned from this comment about finish_return_stmt:
if (needs_post && DECL_POST_FN (current_function_decl) != error_mark_node)
{
vec<tree, va_gc> *args = build_arg_list (current_function_decl);
if (DECL_UNCHECKED_RESULT (current_function_decl))
vec_safe_push (args, expr); // FIXME do we need forward_parm or similar?
if (undeduced_auto_decl (DECL_POST_FN (current_function_decl)))
apply_post_deduced_return_type (current_function_decl,
TREE_TYPE (expr));
push_deferring_access_checks (dk_no_check);
tree call = finish_call_expr (DECL_POST_FN (current_function_decl), &args,
/*disallow_virtual=*/true,
/*koenig_p=*/false,
/*complain=*/tf_warning_or_error);
gcc_assert (call != error_mark_node);
pop_deferring_access_checks ();
/* Replace returned expression with call to post function. */
expr = call;
}This looks like you pass the returned expression as an argument to the post function instead of using it to initialize the return value. That will break copy elision.
What if instead (for a class return type at least) you initialize the return value, then pass a reference to the return value to the post function? Then you could also share the call to the post function between all returns.
This sounds like an intermediate step to doing the return=>goto transform used by cdtor returns? Is there something more general we can leverage even on small by-copy returns? Is it ok to build a reference to an undeduced auto for the DECL_POST_FN of deduced return type functions or is that going to cause issues?
This call has since been marked CALL_FROM_THUNK_P in cases where it really is a CALL_EXPR due to another comment, though this likely doesn't fully address it.
Not sure how we test this specifically. A throwing copy ctor?