currently rewriting my C++ courses from some time back, and wanted
to demonstrate a simply narrowing error; to wit:
int
main()
{
bool b1 {true};
bool b2 {false};
bool b3 {7}; // narrowing error?
int i {42};
int j {42.1}; // narrowing error?
}
oddly, if i use "clang -std=c++11 narrow.cpp", both of those
narrowing conversions are flagged, but if i use "g++ -std=c++11
narrow.cpp", only the second is flagged -- g++ seems fine with
narrowing an int to a bool, even though stroustrup's book on C++11
clearly suggests that should be an error as long as one uses C++ style
curly brace initialization:
bool b1 = 7; // 7!=0, so b becomes true
bool b2 {7}; // error : narrowing (§2.2.2, §10.5)
any C++ wizards out there want to comment on this?
rday