Title
Missing Annex C entry for conflicting declarations in for-loops
Status
tentatively ready
Section
6.4.3 [basic.scope.block]
Submitter
Jay Ghiron

Created on 2026-08-21.00:00:00 last changed yesterday

Messages

Date: 2026-09-03.23:06:47

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.
Date: 2026-08-21.00:00:00

(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.

History
Date User Action Args
2026-09-03 23:06:47adminsetstatus: open -> tentatively ready
2026-08-23 07:35:31adminsetmessages: + msg8658
2026-08-21 00:00:00admincreate