Skip to content

warnings "c++20-attribute-extensions" when compiling with clang and std=c++17 #427

Open

Description

@rizzardf

Hello,

Including the library and compiling with clang++ with "-pedantic" and "-std=c++17" options causes two "c++20-attribute-extensions" warnings. This seems because clang exposes the "unlikely" attribute even if not supported by the c++17 standard but then gives the warning with the "-pedantic" flag.

The issue can be reproduced easily with the library release 8.3.2. It is sufficient to include the library in an empty main.cpp and run:

$ clang++ -pedantic -std=c++17 main.cpp

The output of the command:

In file included from main.cpp:1:
In file included from ./inc/fast_float/fast_float.h:90:
In file included from ./inc/fast_float/parse_number.h:4:
./inc/fast_float/ascii_number.h:625:8: warning: use of the 'unlikely' attribute is a C++20 extension [-Wc++20-attribute-extensions]
  625 |     if fastfloat_unlikely (uint64_t(options.format &
      |        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  626 |                                     detail::basic_javascript_fmt)) {
      |                                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./inc/fast_float/float_common.h:271:37: note: expanded from macro 'fastfloat_unlikely'
  271 | #define fastfloat_unlikely(x) (x) [[unlikely]]
      |                                   ~~^~~~~~~~~~
In file included from main.cpp:1:
In file included from ./inc/fast_float/fast_float.h:90:
./inc/fast_float/parse_number.h:388:6: warning: use of the 'unlikely' attribute is a C++20 extension [-Wc++20-attribute-extensions]
  388 |   if fastfloat_unlikely (uint64_t(fmt & detail::basic_javascript_fmt)) {
      |      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./inc/fast_float/float_common.h:271:37: note: expanded from macro 'fastfloat_unlikely'
  271 | #define fastfloat_unlikely(x) (x) [[unlikely]]
      |                                   ~~^~~~~~~~~~
2 warnings generated.

I am using clang 20.1.8.

Thank you,
Best regards,
Federico

Activity

  1. Tiancheng-Xu commented on Oct 15, 2026

    @Tiancheng-Xu

    May I take this as a narrow compatibility fix for the fastfloat_unlikely feature guard, separate from the parsing optimizations in #416? I’d add a Clang C++17 pedantic-errors regression and check C++11/14/20 compatibility without changing number-parsing behavior. I haven’t reproduced it locally yet.

  2. rizzardf commented on Oct 16, 2026

    @rizzardf
    Author

    It seems that the issue is somehow partially addressed in other parts of the library. For example, referring to release 8.3.2, parse_number.h at lines 432-469, the warning is already suppressed.

    // Slow path A (rare): > 19 significant digits. The no-span parse left the
      // mantissa un-truncated and skipped the span-based recompute; the cold helper
      // re-parses with spans and runs the full algorithm.
      //
    // 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
    // This is unfortunate.
    #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 (pns.too_many_digits) {
        return parse_number_slow_path<T, UC>(first, last, value, options, bjf);
      }
      answer.ec = std::errc(); // be optimistic
      answer.ptr = pns.lastmatch;
    
      if (clinger_fast_path_impl(pns.mantissa, pns.exponent, pns.negative, value)) {
        return answer;
      }
    
      adjusted_mantissa am =
          compute_float<binary_format<T>>(pns.exponent, pns.mantissa);
      // Slow path B (rare): Eisel-Lemire could not resolve; digit_comp needs the
      // integer/fraction spans. Route to the cold helper (clinger there is a
      // dead-effect since it already failed here; the cold re-parse + digit_comp
      // via from_chars_advanced reproduces this branch).
      if fastfloat_unlikely (am.power2 < 0) {
        return parse_number_slow_path<T, UC>(first, last, value, options, bjf);
      }
      to_float(pns.negative, am, value);
      // Test for over/underflow. Marked unlikely so that clang keeps it as a
      // branch instead of folding it into a chain of conditional moves that
      // every conversion pays for.
      if fastfloat_clang_unlikely ((pns.mantissa != 0 && am.mantissa == 0 &&
                                    am.power2 == 0) ||
                                   am.power2 ==
                                       binary_format<T>::infinite_power()) {
        answer.ec = std::errc::result_out_of_range;
      }
    #ifdef __clang__
    #pragma clang diagnostic pop
    #endif

    However, it is not managed the same at line 388, which is causing one of the compilation warnings.

    You might also refer to #387 (comment).

    Thanks,
    Best regards,
    Federico

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions