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
At the top of clause 15, in paragraph 2, it says:
A goto, break, return, or continue statement can be used to transfer control out of a try block or handler, but not into one.What about switch statements?
switch ( f() ) { case 1: try { g(); case 2: h(); } catch (...) { // handler } break; }Daveed Vandevoorde:
Consider:
void f() { try { label: ; } catch(...) { goto label; } }Now the phrase "try block" (without a hyphen) is used in paragraph 1 in a way that causes me to think that it is not intended to include the corresponding handlers. On the other hand, the grammar entity "try-block" (with hyphen) does include the handlers. So is the intent to prohibit the above or not?
Proposed resolution (10/00:
Change text in Clause 14 [except] paragraph 2 from:
A goto, break, return, or continue statement can be used to transfer control out of a try block or handler, but not into one.to:
A goto or switch statement shall not be used to transfer control into a try block or into a handler.
[ Example:void f() {—end example ]
goto l1; // Ill-formed
goto l2; // Ill-formed
try {
goto l1; // OK
goto l2; // Ill-formed
l1: ;
} catch (...) {
l2: ;
goto l1; // Ill-formed
goto l2; // OK
}
}
A goto, break, return, or continue statement can be used to transfer control out of a try block or handler.
(See also issue 246.)