danielaparker / jsoncons

A C++, header-only library for constructing JSON and JSON-like data formats, with JSON Pointer, JSON Patch, JSON Schema, JSONPath, JMESPath, CSV, MessagePack, CBOR, BSON, UBJSON
https://danielaparker.github.io/jsoncons
Other
726 stars 164 forks source link

Current build fails with MinGW 11.2 because it doesn't have std::from_chars() #398

Closed JohannAnhofer closed 1 year ago

JohannAnhofer commented 2 years ago

Out build fails with gcc on windows (MinGW) because it doesn't find the std::from_chars() function.

parse_number.hpp:948:41: error: no matching function for call to 'from_chars(char*, char*, double&)'
const auto res = std::from_chars(input.data(), input.data() + len, val);

in compiler_support.hpp there is already a detection of the feature, but this doesn't work for MinGW (GCC 11.2.0)

#if !defined(JSONCONS_HAS_STD_FROM_CHARS)
#  if defined(__GNUC__)
#   if (__GNUC__ >= 11)
#    if (__cplusplus >= 201703)
#     define JSONCONS_HAS_STD_FROM_CHARS 1
#    endif // (__cplusplus >= 201703)
#   endif // (__GNUC__ >= 11)
#  endif // defined(__GNUC__)
#  if defined(_MSC_VER)
#   if (_MSC_VER >= 1924 && _MSVC_LANG >= 201703)
#    define JSONCONS_HAS_STD_FROM_CHARS 1
#   endif // (_MSC_VER >= 1924 && MSVC_LANG >= 201703)
#  endif // defined(_MSC_VER)
#endif
#if defined(JSONCONS_HAS_STD_FROM_CHARS)
#include <charconv>
#endif

To make this work for MinGW (skip the std::from_chars)

#if !defined(JSONCONS_HAS_STD_FROM_CHARS)
#  if defined(__GNUC__)
#   if (__GNUC__ >= 11)
#    if (__cplusplus >= 201703)
#     if !defined(__MINGW32__)
#      define JSONCONS_HAS_STD_FROM_CHARS 1
#     endif // !defined(__MINGW32__)
#    endif // (__cplusplus >= 201703)
#   endif // (__GNUC__ >= 11)
#  endif // defined(__GNUC__)
#  if defined(_MSC_VER)
#   if (_MSC_VER >= 1924 && _MSVC_LANG >= 201703)
#    define JSONCONS_HAS_STD_FROM_CHARS 1
#   endif // (_MSC_VER >= 1924 && MSVC_LANG >= 201703)
#  endif // defined(_MSC_VER)
#endif
#if defined(JSONCONS_HAS_STD_FROM_CHARS)
#include <charconv>
#endif

What compiler, architecture, and operating system?

What jsoncons library version?

danielaparker commented 2 years ago

Thanks. Would you consider providing a PR with this fix? It's easier to credit contributions that way.

danielaparker commented 1 year ago

Fix is in 0.170.0