Commit 5671d3ac authored by Adam Reichold's avatar Adam Reichold Committed by Albert Astals Cid

Extend checked operations header with support for Clang in addition to...

Extend checked operations header with support for Clang in addition to checking for GCC version 5 or later.
parent ed28a561
...@@ -13,8 +13,12 @@ inline bool checkedAssign(long long lz, int *z) { ...@@ -13,8 +13,12 @@ inline bool checkedAssign(long long lz, int *z) {
return false; return false;
} }
#ifndef __has_builtin
#define __has_builtin(x) 0
#endif
inline bool checkedAdd(int x, int y, int *z) { inline bool checkedAdd(int x, int y, int *z) {
#if __GNUC__ >= 5 #if __GNUC__ >= 5 || __has_builtin(__builtin_sadd_overflow)
return __builtin_sadd_overflow(x, y, z); return __builtin_sadd_overflow(x, y, z);
#else #else
const auto lz = static_cast<long long>(x) + static_cast<long long>(y); const auto lz = static_cast<long long>(x) + static_cast<long long>(y);
...@@ -23,7 +27,7 @@ inline bool checkedAdd(int x, int y, int *z) { ...@@ -23,7 +27,7 @@ inline bool checkedAdd(int x, int y, int *z) {
} }
inline bool checkedMultiply(int x, int y, int *z) { inline bool checkedMultiply(int x, int y, int *z) {
#if __GNUC__ >= 5 #if __GNUC__ >= 5 || __has_builtin(__builtin_smul_overflow)
return __builtin_smul_overflow(x, y, z); return __builtin_smul_overflow(x, y, z);
#else #else
const auto lz = static_cast<long long>(x) * static_cast<long long>(y); const auto lz = static_cast<long long>(x) * static_cast<long long>(y);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment