Created on 2025-08-02.00:00:00 last changed 2 weeks ago
Suggested resolution:
Change in 8.8.4 [stmt.return] paragraph 2 as follows:
... A return statement with no operand shallbe usedappear as a non-discarded statement (8.5.2 [stmt.if]) only in a function whose return type is cv void, a constructor (11.4.5 [class.ctor]), or a destructor (11.4.7 [class.dtor]). A return statement with an operand of type void shallbe usedappear as a non-discarded statement only in a function that has a cv void return type. A return statement with any other operand shallbe usedappear as a non-discarded statement only in a function that has a return type other than cv void; such a non-discarded return statement initializes the returned reference or prvalue result object of the (explicit or implicit) function call by copy-initialization (9.5 [dcl.init]) from the operand.
(From submission #737.)
Consider:
auto f() { if constexpr (false) return; return 3; }
Is this well-formed? The first return statement is discarded, so the return type is not deduced from it. However, 8.8.4 [stmt.return] paragraph 2 still seems to apply; discarded return statements are not excluded:
... A return statement with no operand shall be used only in a function whose return type is cv void, a constructor (11.4.5 [class.ctor]), or a destructor (11.4.7 [class.dtor]). A return statement with an operand of type void shall be used only in a function that has a cv void return type. A return statement with any other operand shall be used only in a function that has a return type other than cv void; ...
History | |||
---|---|---|---|
Date | User | Action | Args |
2025-08-13 22:26:32 | admin | set | messages: + msg8073 |
2025-08-02 00:00:00 | admin | create |