This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 119a. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.
2025-12-20
[Adopted at the February/March, 2017 meeting.]
Given an example like
void f() { int arr[] = { 1, 2, 3 }; for (int val : arr) { int val; // Redeclares index variable } }one might expect that the redeclaration of the index variable wouldbe an error, as it is in the corresponding classicforstatement. However, the restriction that makes the latter an error isphrased in terms of thecondition nonterminal in8.5 [stmt.select] paragraph 3, and the range-basedfordoes not refer tocondition. Should there be an explicitprohibition of such a redeclaration?
Proposed resolution (January, 2017):
Add the following as a new paragraph after 8.6 [stmt.iter] paragraph 3:
Thus after thewhile statement,i is no longer inscope. —end example]
If a name introduced in aninit-statementorfor-range-declaration is redeclared in the outermost block of thesubstatement, the program is ill-formed. [Example:
void f() { for (int i = 0; i < 10; ++i) int i = 0; // error: redeclaration for (int i : { 1, 2, 3 }) int i = 1; // error: redeclaration }—end example]