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

2025-08-11


3045. Regularizing environment interactions of expansion statement

Section: 6.4.3  [basic.scope.block]     Status: open     Submitter: Jakub Jelinek     Date: 2025-07-18

(From submission #729.)

Consider:

  template for (auto x : whatever) {
    int x = 42;
  }

This is valid, but the parallel for-range-statement is not:

  for (auto g : whatever) {
    int g = 42;
  }

Furthermore, due to the possibly surprising rewriting nature of expansion statements, 9.13.5 [dcl.attr.fallthrough] should prohibit [[fallthrough]].

Possible suggested resolution:

  1. Change in 6.4.3 [basic.scope.block] paragraph 2 as follows:

    If a declaration that is not a name-independent declaration and that binds a name in the block scope S of a
    • compound-statement of a lambda-expression, function-body, or function-try-block,
    • substatement of a selection or , iteration, or expansion statement that is not itself a selection or , iteration, or expansion statement, or
    • handler of a function-try-block
    potentially conflicts with a declaration whose target scope is the parent scope of S, the program is ill-formed.
  2. Change in 9.13.5 [dcl.attr.fallthrough] paragraph 1 as follows:

    The attribute-token fallthrough may be applied to a null statement (8.3 [stmt.expr]); such a statement is a fallthrough statement. No attribute-argument-clause shall be present. A fallthrough statement may only appear within an enclosing switch statement (8.5.3 [stmt.switch]). The next statement that would be executed after a fallthrough statement shall be a labeled statement whose label is a case label or default label for the same switch statement and, if the fallthrough statement is contained in an iteration statement, the next statement shall be part of the same execution of the substatement of the innermost enclosing iteration statement. The program is ill-formed if there is no such statement. The innermost enclosing switch statement of a fallthrough statement S shall be contained in the innermost enclosing expansion statement (8.7 [stmt.expand]) of S, if any.