diff --git a/include/nlohmann/detail/input/number_parse.hpp b/include/nlohmann/detail/input/number_parse.hpp index 29be3a67e..e50c3f67f 100644 --- a/include/nlohmann/detail/input/number_parse.hpp +++ b/include/nlohmann/detail/input/number_parse.hpp @@ -16,9 +16,15 @@ #include -#if defined(JSON_HAS_CPP_17) - #include // from_chars (only used when __cpp_lib_to_chars is defined) - #include // errc +// std::from_chars lives in , but being in C++17 mode does not +// guarantee the header exists: GCC 7 sets __cplusplus to C++17 yet ships no +// (added in GCC 8; floating-point support in GCC 11). Guard the +// include with __has_include so such toolchains fall back to the scalar path. +#if defined(JSON_HAS_CPP_17) && defined(__has_include) + #if __has_include() + #include // from_chars (only used when __cpp_lib_to_chars is defined) + #include // errc + #endif #endif // This file contains the value-conversion helpers used by the lexer to turn an diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index f7dd2b705..70ed6f75d 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -7799,9 +7799,15 @@ NLOHMANN_JSON_NAMESPACE_END // #include -#if defined(JSON_HAS_CPP_17) - #include // from_chars (only used when __cpp_lib_to_chars is defined) - #include // errc +// std::from_chars lives in , but being in C++17 mode does not +// guarantee the header exists: GCC 7 sets __cplusplus to C++17 yet ships no +// (added in GCC 8; floating-point support in GCC 11). Guard the +// include with __has_include so such toolchains fall back to the scalar path. +#if defined(JSON_HAS_CPP_17) && defined(__has_include) + #if __has_include() + #include // from_chars (only used when __cpp_lib_to_chars is defined) + #include // errc + #endif #endif // This file contains the value-conversion helpers used by the lexer to turn an