From defb5e48f2dd6c3c483c76c9bfe9b8e5fde5e246 Mon Sep 17 00:00:00 2001 From: Jisan Halder Date: Sun, 18 Oct 2026 19:44:06 +0530 Subject: [PATCH] Guard [[unlikely]] attribute use with C++20 language check (fixes #427) Clang recognizes `__has_cpp_attribute(unlikely)` even when compiling in C++17 mode (`-std=c++17`), but using `[[unlikely]]` before C++20 emits `-Wc++20-attribute-extensions` under `-pedantic`. Require C++20 or later (`__cplusplus >= 202002L` or `_MSVC_LANG >= 202002L`) before enabling `FASTFLOAT_USE_UNLIKELY_ATTR`. Pre-C++20 builds on GCC and Clang will continue to use `__builtin_expect(!!(x), 0)` without extension warnings. Fixes #427 Co-authored-by: ByteAsk --- include/fast_float/float_common.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/fast_float/float_common.h b/include/fast_float/float_common.h index 60c28c7..19027cd 100644 --- a/include/fast_float/float_common.h +++ b/include/fast_float/float_common.h @@ -257,6 +257,7 @@ using parse_options = parse_options_t; // (the macro supplies the parentheses). It expands to the standard [[unlikely]] // attribute when supported, otherwise to __builtin_expect on GCC/Clang, or // to a no-op elsewhere (e.g. pre-C++20 MSVC, which has no equivalent hint). +#if (defined(__cplusplus) && __cplusplus >= 202002L) || (defined(_MSVC_LANG) && _MSVC_LANG >= 202002L) #ifdef __has_cpp_attribute #if __has_cpp_attribute(unlikely) >= 201803L // g++-9 hits hits this branch, but then fails to compile @@ -266,6 +267,7 @@ using parse_options = parse_options_t; #endif #endif #endif +#endif #ifdef FASTFLOAT_USE_UNLIKELY_ATTR #define fastfloat_unlikely(x) (x) [[unlikely]]