Created on 2011-08-16.00:00:00 last changed 131 months ago
[Voted into the WP at the February, 2012 meeting; moved to DR at the October, 2012 meeting.]
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]
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.)
History | |||
---|---|---|---|
Date | User | Action | Args |
2014-03-03 00:00:00 | admin | set | status: drwp -> cd3 |
2012-11-03 00:00:00 | admin | set | status: dr -> drwp |
2012-02-27 00:00:00 | admin | set | messages: + msg3805 |
2012-02-27 00:00:00 | admin | set | status: ready -> dr |
2011-09-06 00:00:00 | admin | set | messages: + msg3457 |
2011-08-16 00:00:00 | admin | create |