From 78b6a96f28b9a7b66a4d95a34fb3ed9edbb73163 Mon Sep 17 00:00:00 2001 From: CODER-7777 Date: Thu, 29 Oct 2026 05:53:02 +0530 Subject: [PATCH] Silence -Wc++20-extensions at the remaining [[unlikely]] sites (fixes #427) The javascript early-exit checks added in b2e41e8 use fastfloat_unlikely without the point-of-use clang diagnostic guard that the other call sites have (see #387), so clang with -pedantic in C++11/14/17 mode warns "use of the 'unlikely' attribute is a C++20 extension". Wrap both sites with the same guarded pragma push/pop already used in parse_number.h and decimal_to_binary.h. No change to code generation. Add a CI step compiling fast_float.h with clang-14 and -pedantic-errors -Werror in C++11/14/17/20 to catch regressions. --- .github/workflows/ubuntu22-clang.yml | 10 +++++++++- include/fast_float/ascii_number.h | 12 ++++++++++++ include/fast_float/parse_number.h | 10 ++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ubuntu22-clang.yml b/.github/workflows/ubuntu22-clang.yml index 5f29203..90331b8 100644 --- a/.github/workflows/ubuntu22-clang.yml +++ b/.github/workflows/ubuntu22-clang.yml @@ -9,6 +9,14 @@ jobs: - uses: actions/checkout@v7 - name: Install clang++-14 run: sudo apt-get install -y clang++-14 + - name: Check for pedantic warnings in pre-C++20 modes (issue 427) + run: | + set -xe + printf '#include "fast_float/fast_float.h"\nint main() { return 0; }\n' > pedantic_check.cpp + for std in c++11 c++14 c++17 c++20; do + clang++-14 -std=$std -Wall -Wextra -pedantic-errors -Werror \ + -Iinclude -fsyntax-only pedantic_check.cpp + done - name: Use cmake run: | mkdir build && @@ -22,4 +30,4 @@ jobs: cd build20 && CXX=clang++-14 cmake -DFASTFLOAT_CONSTEXPR_TESTS=ON -DFASTFLOAT_CXX_STANDARD=20 -DFASTFLOAT_TEST=ON .. && cmake --build . && - ctest --output-on-failure \ No newline at end of file + ctest --output-on-failure diff --git a/include/fast_float/ascii_number.h b/include/fast_float/ascii_number.h index 28d6113..cd69e93 100644 --- a/include/fast_float/ascii_number.h +++ b/include/fast_float/ascii_number.h @@ -622,10 +622,22 @@ parse_number_string(UC const *p, UC const *pend, parse_options_t options, // JSON and JavaScript are mutually exclusive, so only the non-JSON // instantiation has to look at the flag. FASTFLOAT_IF_CONSTEXPR17(!basic_json_fmt) { + // We have to disable -Wc++20-extensions for the [[unlikely]] attribute + // See comment for @jwakely at + // https://github.com/fastfloat/fast_float/pull/387#discussion_r3366943539 +#ifdef __clang__ +#pragma clang diagnostic push +#if (!defined(__APPLE_CC__) && __clang_major__ >= 10) || (__clang_major__ >= 13) +#pragma clang diagnostic ignored "-Wc++20-extensions" +#endif +#endif if fastfloat_unlikely (uint64_t(options.format & detail::basic_javascript_fmt)) { return parse_number_string_javascript(p, pend, options, store_spans); } +#ifdef __clang__ +#pragma clang diagnostic pop +#endif } return parse_number_string_impl(p, pend, options, store_spans); diff --git a/include/fast_float/parse_number.h b/include/fast_float/parse_number.h index d12a442..ed823fb 100644 --- a/include/fast_float/parse_number.h +++ b/include/fast_float/parse_number.h @@ -391,9 +391,19 @@ from_chars_float_advanced(UC const *first, UC const *last, T &value, // Leave for the javascript conversion before anything else is live, so this // compiles to a tail call and the common path keeps its registers. The cold // function repeats the leading-whitespace and empty-input handling below. + // See the comment on -Wc++20-extensions further down in this function. +#ifdef __clang__ +#pragma clang diagnostic push +#if (!defined(__APPLE_CC__) && __clang_major__ >= 10) || (__clang_major__ >= 13) +#pragma clang diagnostic ignored "-Wc++20-extensions" +#endif +#endif if fastfloat_unlikely (uint64_t(fmt & detail::basic_javascript_fmt)) { return from_chars_float_javascript(first, last, value, options); } +#ifdef __clang__ +#pragma clang diagnostic pop +#endif from_chars_result_t answer; if (uint64_t(fmt & chars_format::skip_white_space)) {