Consider this code:
#include <iostream>
int main()
{
int i{10.1}; // narrowing, should not compile
std::cout << i << std::endl;
}
According to the C++11 standard, it should not compile (narrowing in brace initialization is forbidden.)
Now, compiling with g++4.9.2 -std=c++11
only emits a warning
warning: narrowing conversion of '1.01e+1' from 'double' to 'int' inside { } [-Wnarrowing]
Removing the -std=c++11
flag results in a warning regarding the brace init, but not any narrowing:
warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
On the other hand, g++5 doesn't compile it, provided you compile with g++5 -std=c++11
. However, if -std=c++11
is omitted, then even g++5
happily compiles it, giving just a warning related to the brace init, not to the narrowing:
warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
The above behaviour seems buggy, g++4.9
should not compile the code, and it is more than weird that g++5
compiles it if you forget to specify -std=c++11
. Is this a known problem?