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

2026-09-04


3221. Missing Annex C entry for conflicting declarations in for-loops

Section: 6.4.3  [basic.scope.block]     Status: tentatively ready     Submitter: Jay Ghiron     Date: 2026-08-21

(From submission #984.)

Consider:

  void f() {
    for (int i = 0; ; ) {
      long i = 1;  // valid C, invalid C++
      // ...
    }
  }

See also C DR 466 for the history of the divergence.

Proposed resolution (approved by CWG 2026-09-01):

Add in C.8.3 [diff.basic] as follows:

Affected subclause: 6.4.3 [basic.scope.block]
Change: Names declared in the outermost block scope of a for loop conflict with those declared in its init-statement.
[ Example:
  void f() {
    for (int i = 0; ; ) {
      long i = 1;  // valid C, invalid C++
      // ...
    }
  }
-- end example]
Rationale: C99 introduced the possibility to declare variables in a for loop, but did not add C++' rule about conflicting declarations.
Effect on original feature: Change to semantics of well-defined feature.
Difficulty of converting: Syntactic transformation.
How widely used: Seldom.