Title
Flowing off end is not equivalent to no-expression return
Status
cd4
Section
8.7.4 [stmt.return]
Submitter
Richard Smith

Created on 2014-10-06.00:00:00 last changed 87 months ago

Messages

Date: 2015-10-15.00:00:00

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]).
Date: 2015-11-10.00:00:00

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.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.
Date: 2016-02-15.00:00:00

[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.

History
Date User Action Args
2017-02-06 00:00:00adminsetstatus: ready -> cd4
2015-11-10 00:00:00adminsetmessages: + msg5574
2015-11-10 00:00:00adminsetmessages: + msg5573
2015-05-25 00:00:00adminsetmessages: + msg5452
2015-05-25 00:00:00adminsetstatus: drafting -> ready
2014-10-06 00:00:00admincreate