This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 115e. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.
2024-11-11
[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_list<int> in 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<int> auto x2 = { 1, 2.0 }; // error: cannot deduce element type const auto &i = expr;The type of i is the deduced type of the parameter u in the call f(expr) of the following invented function template:
template <class U> void f(const U& u);—end example]
If the
list of declaratorsinit-declarator-list contains more than onedeclaratorinit-declarator, the type of each declared variable is determined as described above. If the typededuced for the template parameter Uthat 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 parameter u in the call f(expr) of the following invented function template:template <class U> 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]