This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 112e. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.

2023-12-02


2495. Glvalue result of a function call

Section: 8.7.4  [stmt.return]     Status: open     Submitter: Jim X     Date: 2021-07-04

According to 8.7.4 [stmt.return] paragraph 1,

A return statement with any other operand shall be used only in a function whose return type is not cv void; the return statement initializes the glvalue result or prvalue result object of the (explicit or implicit) function call by copy-initialization (9.4 [dcl.init]) from the operand.

It is not clear what a “glvalue result” is or what it means to initialize it.

Suggested resolution:

A return statement with any other operand shall be used only in a function whose return type is not cv void;. If the function call is a prvalue, the return statement initializes the glvalue result or prvalue result object of the (explicit or implicit) function call by copy-initialization (9.4 [dcl.init]) from the operand. Otherwise, the return statement is equivalent to the following hypothetical declaration

If the operand of the return statement, X, is a comma expression without parentheses, e is (X), otherwise e is X. T is the return type of the function call; the invented variable t is the result of the function call.

Notes from the August, 2021 teleconference:

A simpler approach would be simply to use a phrase like “returned object or reference” in place of the current wording referring to glvalues and prvalues. This change was regarded as editorial. The issue will remain in "review" status until CWG can look over the wording change.