6 Once the type of a declarator-id has been determined according to 8.3, the type of the declared variable
using the declarator-id is determined from the type of its initializer using the rules for template argument
deduction. Let T be the type that has been determined for a variable identifier d. Obtain P from T by
replacing the occurrences of auto with either a new invented type template parameter U or, if the initializer
is a braced-init-list (8.5.4), with std::initializer_list<U>. The type deduced for the variable d is then
the deduced type determined using the rules of template argument deduction from a function call (14.9.2.1),
where P is a function template parameter type and the initializer for d is the corresponding argument. If
the deduction fails, the declaration is ill-formed. [ Example:
auto x1 = { 1, 2 }; // decltype(x1) is std::initializer_list<int>
auto x2 = { 1, 2.0 }; // error: cannot deduce element type
—end example ]
Partager