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

2024-11-11


2017. Flowing off end is not equivalent to no-expression return

Section: 8.7.4  [stmt.return]     Status: CD4     Submitter: Richard Smith     Date: 2014-10-06

[Adopted at the February, 2016 meeting.]

According to 8.7.4 [stmt.return] paragraph 2,

Flowing off the end of a function is equivalent to a return with no value...

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.

Proposed resolution (May, 2015): [SUPERSEDED]

Change 8.7.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.

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.

Proposed resolution (October, 2015):

  1. Change 6.9.3.1 [basic.start.main] paragraph 5 as follows:

  2. 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 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;
    
  3. Change 8.7.4 [stmt.return] paragraph 2 as follows:

  4. ...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.9.3.1 [basic.start.main] results in undefined behavior.
  5. Change 14.4 [except.handle] paragraph 14 as follows:

  6. 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.7.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.7.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.7.4 [stmt.return]).