CWG Issue 1347 (original) (raw)

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

2025-11-05


1347. Consistency of auto in multiple-declarator declarations

Section: 9.2.9.7 [dcl.spec.auto]Status: CD3Submitter: Richard SmithDate: 2011-08-16

[Voted into the WP at the February, 2012 meeting; moved to DR at the October, 2012 meeting.]

The intent of 9.2.9.7 [dcl.spec.auto] paragraph 7 appears to have been that the type represented by auto should be the same for each declarator in the declaration. However, the current wording does not achieve that goal. For example, in

auto a = 0, b = { 1, 2, 2 };

the auto specifier represents int in the first declarator and std::initializer_listin the second. (See also issue 1265.)

Proposed resolution (August, 2011):

Move the example in 9.2.9.7 [dcl.spec.auto] paragraph 7 into that of paragraph 6 and change paragraph 7 as follows:

...[Example:

auto x1 = { 1, 2 }; // decltype(x1) is std::initializer_list auto x2 = { 1, 2.0 }; // error: cannot deduce element type

const auto &i = expr;

The type of i is the deduced type of the parameteru in the call f(expr) of the following invented function template:

template void f(const U& u);

—_end example_]

If the list of declarators init-declarator-list contains more than onedeclarator init-declarator, the type of each declared variable is determined as described above. If the typededuced for the template parameter U that replaces the occurrence of auto is not the same in each deduction, the program is ill-formed.

[Example:

const auto &i = expr;

The type of i is the deduced type of the parameteru in the call f(expr) of the following invented function template:

template void f(const U& u); auto x = 5, *y = &x; // OK: auto is int auto a = 5, b = { 1, 2 }; // error: different types for auto

—_end example_]