From f11e6beca82b92ba456d8c472b1e2bc8d2b1b708 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 17 Dec 2022 20:09:21 +0100 Subject: [PATCH] AK: Use __has_builtin() in Checked.h Instead of avoiding overflow-checking builtins with AK_COMPILER_CLANG, we can use the preprocessor's __has_builtin() mechanism to check if they are available. --- AK/Checked.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/AK/Checked.h b/AK/Checked.h index 7026c49302..06fd95980f 100644 --- a/AK/Checked.h +++ b/AK/Checked.h @@ -328,26 +328,26 @@ public: template [[nodiscard]] static constexpr bool addition_would_overflow(U u, V v) { -#if defined(AK_COMPILER_CLANG) +#if __has_builtin(__builtin_add_overflow_p) + return __builtin_add_overflow_p(u, v, (T)0); +#else Checked checked; checked = u; checked += v; return checked.has_overflow(); -#else - return __builtin_add_overflow_p(u, v, (T)0); #endif } template [[nodiscard]] static constexpr bool multiplication_would_overflow(U u, V v) { -#if defined(AK_COMPILER_CLANG) +#if __has_builtin(__builtin_mul_overflow_p) + return __builtin_mul_overflow_p(u, v, (T)0); +#else Checked checked; checked = u; checked *= v; return checked.has_overflow(); -#else - return __builtin_mul_overflow_p(u, v, (T)0); #endif }