This code gives me no warnings when compiled with g++
:
unsigned int myFunc(unsigned int integer) {
return integer;
}
int main() {
int x = -1;
std::cout << myFunc(x) << std::endl;
}
It compiles fine but the result is wrong: 4294967295
. Does GCC have any compiler -W*
options for that?
Yes, -Wsign-conversion
Beware that -Wconversion
doesn't enable this warning for C++ code, although it does for C code.