-
Notifications
You must be signed in to change notification settings - Fork 7
Description
Reference (section label): [stmt.return]
Issue description:
It's unclear whether this example is intended to be valid:
auto f() {
if constexpr (false) return;
return 3;
}
The first return
statement is discarded, so we do not use it when deducing the return type. (Although one implementation does, and rejects for that reason; the remaining tested implementations accept.) However, [stmt.return]/2 still appears to apply:
[...] A return statement with no operand shall be used only in a function whose return type is cv void, a constructor ([class.ctor]), or a destructor ([class.dtor]).
Nothing seems to exclude discarded return statements from this check. Presumably they should be excluded.
Suggested resolution:
Change in [stmt.return]/2:
The expr-or-braced-init-list of a
return
statement is called its operand. Areturn
statement with no operand shallbe usedappear as a non-discarded statement ([stmt.if]) only in a function whose return type is cvvoid
, a constructor ([class.ctor]), or a destructor ([class.dtor]). Areturn
statement with an operand of typevoid
shallbe usedappear as a non-discarded statement only in a function that has a cvvoid
return type. Areturn
statement with any other operand shallbe usedappear as a non-discarded statement only in a function that has a return type other than cvvoid
;thesuch a non-discardedreturn
statement initializes the returned reference or prvalue result object of the (explicit or implicit) function call by copy-initialization from the operand.
This change also clarifies that the semantic constraints for copy-initialization of the return object from the argument are not checked for a discarded return
statement.