Avec Clang 3.7 (Coliru), avec le code :
| auto a {3};
std::cout << a << std::endl;
|
affiche l'erreur :
| main.cpp:70:12: warning: direct list initialization of a variable with a deduced type will
change meaning in a future version of Clang; insert an '=' to avoid a change in behavior
[-Wfuture-compat]
auto a {3};
^
=
main.cpp:71:15: error: invalid operands to binary expression ('ostream' (aka
'basic_ostream<char>') and 'std::initializer_list<int>')
std::cout << a << std::endl;
~~~~~~~~~ ^ ~
|
Mais effectivement, avec GCC 5.2 (sur Coliru aussi), cela ne produit pas de warning.
Après recherche : http://llvm.org/releases/3.6.0/tools/clang/docs/ReleaseNotes.html et http://scottmeyers.blogspot.co.uk/2015/09/thoughts-on-vagaries-of-c-initialization.html
An upcoming change to C++ <http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n3922.html>_ changes the semantics of certain deductions of auto from a braced initializer list. Following the intent of the C++ committee, this change will be applied to our C++11 and C++14 modes as well as our experimental C++17 mode. Clang 3.6 does not yet implement this change, but to provide a transition period, it warns on constructs whose meaning will change. The fix in all cases is to add an = prior to the left brace.
Several compilers have implemented N3922. In fact, it can be hard—maybe even impossible— to get such compilers to adhere to the C++14 standard, even if you want them to. GCC 5.1 follows the N3922 rule even when expressly in C++11 or C++14 modes, i.e., when compiled with -std=c++11 or -std=c++14. Visual C++ 2015 is similar: type deduction is performed in accord with N3922, even when /Za ("disable language extensions") is used.
Donc c'est un peu vicieux. C'est bien du C++1z, mais considéré comme une erreur du C++11/14. Du coup, les compilateurs activent cette option par défaut quand on active C++11/14… Donc ok, on peut effectivement le mettre dans un cours C++11/14.