I would've expected an initialiser would only be necessary for the first declaration. e.g.
auto x = 2, y;
I would expect this to deduce x's type as int and then implicitly replace "auto" with the base type "int", meaning y would then be a default initialised integer. Actually the entire thing doesn't compile because y explicitly needs and initialiser. Similarly it's odd to me that
auto x = 2, y = 3.3;
causes an error too. I would've expected y to be initialsed to 3 in a double-to-int conversion, but:
error: inconsistent deduction for 'auto': 'int' and then 'double'
I read through http://ift.tt/1qVqFKT and couldn't explicitly find an explanation. Actually it seemed like that link was on my side:
Once the type of the initializer has been determined, the compiler determines the type that will replace the keyword auto using the rules for template argument deduction from a function call (see template argument deduction#Other contexts for details).
Is it simply "just cause"?
Aucun commentaire:
Enregistrer un commentaire