Title
Imprecise restrictions on break and continue
Status
ready
Section
Clause [8] [stmt.stmt]
Submitter
Jim X

Created on 2022-08-24.00:00:00 last changed 1 month ago

Messages

Date: 2022-08-26.21:45:07

Proposed resolution (approved by CWG 2022-08-26):

  1. Append to 8.1 [stmt.pre] paragraph 3 as follows:

    ... A statement S1 is enclosed by a statement S2 if S2 encloses S1.

    The rules for conditions apply both...

  2. Change in 8.2 [stmt.label] paragraph 2 as follows:

    Case labels and default labels shall occur only in switch statements A labeled-statement whose label is a case or default label shall be enclosed by (8.1 [stmt.pre]) a switch statement (8.5.3 [stmt.switch])..
  3. Change in 8.7.2 [stmt.break] paragraph 1 as follows:

    The A break statement shall occur only in be enclosed by (8.1 [stmt.pre]) an iteration-statement (8.6 [stmt.iter]) or a switch statement and (8.5.3 [stmt.switch]). The break statement causes termination of the smallest such enclosing iteration-statement or switch statement; control passes to the statement following the terminated statement, if any.
  4. Change in 8.7.3 [stmt.cont] paragraph 1 as follows:

    The A continue statement shall occur only in be enclosed by (8.1 [stmt.pre]) an iteration-statement (8.6 [stmt.iter]) and. The continue statement causes control to pass to the loop-continuation portion of the smallest such enclosing iteration-statement statement, that is, to the end of the loop. ...
Date: 2022-08-26.21:45:07

Consider:

for (int i = 0; i< 10; ++i){
  auto f = [](){
    break; // #1
  };
}

Subclause 8.7.2 [stmt.break] paragraph 1 specifies:

The break statement shall occur only in an iteration-statement or a switch statement and causes termination of the smallest enclosing iteration-statement or switch statement; control passes to the statement following the terminated statement, if any.

Does the break at #1 "occur" in the for loop?

History
Date User Action Args
2022-08-26 21:45:07adminsetmessages: + msg6910
2022-08-26 21:45:07adminsetstatus: open -> ready
2022-08-24 00:00:00admincreate