- Title
- Flowing off end is not equivalent to no-expression return
- Status
- cd4
- Section
- 8.8.4 [stmt.return]
- Submitter
- Richard Smith
Created on 2014-10-06.00:00:00 last changed 116 months ago
Messages
Date: 2015-10-15.00:00:00
Proposed resolution (October, 2015): Change 6.10.3.1 [basic.start.main] paragraph 5 as follows: A return statement in main has the effect of
leaving the main function (destroying any objects with
automatic storage duration) and calling std::exit
with the return value as the argument. If
control Change 8.8.4 [stmt.return] paragraph 2 as follows: Change 14.4 [except.handle] paragraph 14 as follows:
reaches flows off the end
of the compound-statement
of main without encountering
a return statement, the effect is that
of executing equivalent to a return with
operand 0 (see also
14.4 [except.handle]).
return 0;
...Flowing off the end of a function with a void return
type is equivalent to a return with
no
value; this results in undefined behavior in a
value-returning
function operand. Otherwise, flowing
off the end of a function other than main
(6.10.3.1 [basic.start.main] results in undefined
behavior.
The currently handled exception is rethrown if control
reaches the end of a handler of
the function-try-block of a constructor or
destructor. Otherwise,
a function returns when control
reaches the end of a handler for
the function-try-block
(8.8.4 [stmt.return]). Flowing off the end of
a function-try-block is equivalent to
a return with no value; this results in undefined
behavior in a value-returning function
(8.8.4 [stmt.return]) flowing off the
end of the compound-statement of a handler
of a function-try-block is equivalent to flowing
off the end of the compound-statement of that
function (see 8.8.4 [stmt.return]).
Date: 2026-07-25.21:52:10
Additional notes, October, 2015: There is similar wording in 14.4 [except.handle] paragraph 14.
Also, it might be better to avoid the
use of the word “value”, since it is currently
not clearly defined.
Date: 2015-05-15.00:00:00
Proposed resolution (May, 2015): [SUPERSEDED] Change 8.8.4 [stmt.return] paragraph 2 as follows:
...Flowing off the end of a value-returning
function is undefined behavior. Flowing off the end of
any other function is equivalent to a return with no
value
; this results in undefined behavior in a
value-returning function.
Date: 2016-02-15.00:00:00
[Adopted at the February, 2016 meeting.] According to 8.8.4 [stmt.return] paragraph 2, This is not correct, since a return with no value is
ill-formed in a value-returning function but flowing off the end
results in undefined behavior.
Flowing off the end of a function is equivalent to a return
with no value...
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2017-02-06 00:00:00 | admin | set | status: ready -> cd4 |
| 2015-11-10 00:00:00 | admin | set | messages: + msg5574 |
| 2015-11-10 00:00:00 | admin | set | messages: + msg5573 |
| 2015-05-25 00:00:00 | admin | set | messages: + msg5452 |
| 2015-05-25 00:00:00 | admin | set | status: drafting -> ready |
| 2014-10-06 00:00:00 | admin | create | |