I'm trying to compile C++ code with the built-in "add with oveflow check" functions[1]. But the compiler complains the built-ins have not been declared. I'm using g++ 4.9.2. Attached is some minimal code to test. Can anybody help? [1] https://gcc.gnu.org/onlinedocs/gcc/Integer-Overflow-Builtins.html -- Bruno Schneider
#include <iostream> #include <limits> using namespace std; int main() { unsigned int a = numeric_limits<unsigned int>::max(); unsigned int b = 1; unsigned int c = a + b; if (__builtin_uadd_overflow(a, b, &c)) cout << "overflow\n"; else cout << a << " + " << b << " = " << c << "\n"; return 0; }