diff --git a/include/nlohmann/detail/input/number_parse.hpp b/include/nlohmann/detail/input/number_parse.hpp index 1a2d6d489..4da712f81 100644 --- a/include/nlohmann/detail/input/number_parse.hpp +++ b/include/nlohmann/detail/input/number_parse.hpp @@ -263,7 +263,10 @@ expects (side-stepping the P4168 divergence between implementations). template bool parse_float_from_chars(const char* first, const char* last, FloatType& out) noexcept { -#if defined(__cpp_lib_to_chars) + // JSON_HAS_CPP_17 must gate the use as well as the include above: + // some standard libraries (e.g. libstdc++ 15) define __cpp_lib_to_chars even + // in C++14 mode, where is not included. +#if defined(JSON_HAS_CPP_17) && defined(__cpp_lib_to_chars) const auto result = std::from_chars(first, last, out); return result.ec == std::errc() && result.ptr == last; #else diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 240ef7db4..f40630517 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -8046,7 +8046,10 @@ expects (side-stepping the P4168 divergence between implementations). template bool parse_float_from_chars(const char* first, const char* last, FloatType& out) noexcept { -#if defined(__cpp_lib_to_chars) + // JSON_HAS_CPP_17 must gate the use as well as the include above: + // some standard libraries (e.g. libstdc++ 15) define __cpp_lib_to_chars even + // in C++14 mode, where is not included. +#if defined(JSON_HAS_CPP_17) && defined(__cpp_lib_to_chars) const auto result = std::from_chars(first, last, out); return result.ec == std::errc() && result.ptr == last; #else