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

2024-10-26


1732. Defining types in conditions and range-based for statements

Section: 8.5  [stmt.select]     Status: C++14     Submitter: Richard Smith     Date: 2013-08-08

[Moved to DR at the February, 2014 meeting.]

The interaction of various issue resolutions has inadvertently resulted in the loss of the prohibition of defining types in conditions (8.5 [stmt.select] paragraph 1) and in a range-based for (8.6 [stmt.iter] paragraph 1). Issue 686 addressed a patchwork of restrictions by banning type definitions in type-specifier-seqs. Issue 948 then changed the definition of condition to use a decl-specifier-seq instead of a type-specifier-seq in order to permit the constexpr specifier. A similar change was made for range-based for statements by issue 1204.

The restrictions against type definitions in these contexts should be restored.

Proposed resolution (January, 2014):

  1. Change 8.5 [stmt.select] paragraph 2 as follows:

  2. The rules for conditions apply both to selection-statements and to the for and while statements (8.6 [stmt.iter]). The declarator shall not specify a function or an array. The decl-specifier-seq shall not define a class or enumeration. If the auto type-specifier appears in the decl-specifier-seq, the type of the identifier being declared is deduced from the initializer as described in 9.2.9.7 [dcl.spec.auto].
  3. Change 8.6.5 [stmt.ranged] paragraph 2 as follows:

  4. In the decl-specifier-seq of a for-range-declaration, each decl-specifier shall be either a type-specifier or constexpr. The decl-specifier-seq shall not define a class or enumeration.