I had a problem with CLANG compiler for ARM. In release build the code below was optimized in a way that the multiplication and division did not occur as separate operations and no overflow was detected (there should have been an overflow). When I turned off optimization it worked as intended. In the VS 2017 compiler this worked as intended in both release and debug.
Original code that was optimized to "true" as in no overflow detected although there was an overflow:
int64 resDecPart = value1dec * value2dec;
if (resDecPart / value1dec == value2dec) { // no overflow
I changed the code to this and that works in CLANG and VS compiler, both release and debug
if (value1dec != 0 && (std::numeric_limits<int64>::max() / value1dec) >= value2dec) { // no overflow
I had a problem with CLANG compiler for ARM. In release build the code below was optimized in a way that the multiplication and division did not occur as separate operations and no overflow was detected (there should have been an overflow). When I turned off optimization it worked as intended. In the VS 2017 compiler this worked as intended in both release and debug.
Original code that was optimized to "true" as in no overflow detected although there was an overflow:
I changed the code to this and that works in CLANG and VS compiler, both release and debug