Consider the following problematic code:
#include <iostream>
void foo(int64_t y) {
std::cout << y << "\n";
}
int main() {
uint64_t x = 14400000000000000000ull;
foo(x);
}
Typically prints -4046744073709551616.
How can one get the compiler to help with this type of conversion/overflow issue? I have tried the following:
g++ -g overflow.cpp -fsanitize=undefined -Wall -Wextra -pedantic -Wconversion -Wconversion
clang++ -g overflow.cpp -fsanitize=undefined,integer,implicit-conversion -Wall -Wextra -pedantic
None of which gives any compile- or run-time warning.
(clang version 7.0.0, gcc version 8.2.1)