This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 116a. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.
2024-12-19
[Accepted as a DR at the November, 2022 meeting.]
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?
Proposed resolution (approved by CWG 2022-08-26):
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...
Change in 8.2 [stmt.label] paragraph 2 as follows:
Case labels and default labels shall occur only in switch statementsA 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])..
Change in 8.7.2 [stmt.break] paragraph 1 as follows:
TheA break statement shalloccur only inbe enclosed by (8.1 [stmt.pre]) an iteration-statement (8.6 [stmt.iter]) or a switch statementand(8.5.3 [stmt.switch]). The break statement causes termination of the smallest such enclosingiteration-statement or switchstatement; control passes to the statement following the terminated statement, if any.
Change in 8.7.3 [stmt.cont] paragraph 1 as follows:
TheA continue statement shalloccur only inbe 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 enclosingiteration-statementstatement, that is, to the end of the loop. ...