Skip to content

Commit a66c329

Browse files
committed
Provide fallback for missing char8_t support
Clang 11.0.x with libc++ fails to compile tests in C++20 mode due to incomplete char8_t support in std::filesystem::path. Signed-off-by: Sergiu Deitsch <sergiu.deitsch@gmail.com>
1 parent 7ddea26 commit a66c329

3 files changed

Lines changed: 4 additions & 4 deletions

File tree

include/nlohmann/detail/conversions/from_json.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ inline void from_json(const BasicJsonType& j, std_fs::path& p)
540540
JSON_THROW(type_error::create(302, concat("type must be string, but is ", j.type_name()), &j));
541541
}
542542
const auto& s = *j.template get_ptr<const typename BasicJsonType::string_t*>();
543-
#ifdef JSON_HAS_CPP_20
543+
#if defined(__cpp_lib_char8_t) && (__cpp_lib_char8_t >= 201907L)
544544
p = std_fs::path(std::u8string_view(reinterpret_cast<const char8_t*>(s.data()), s.size()));
545545
#else
546546
p = std_fs::u8path(s); // accepts UTF-8 encoded std::string in C++17, deprecated in C++20

include/nlohmann/detail/conversions/to_json.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ inline void to_json(BasicJsonType& j, const T& t)
443443
template<typename BasicJsonType>
444444
inline void to_json(BasicJsonType& j, const std_fs::path& p)
445445
{
446-
#ifdef JSON_HAS_CPP_20
446+
#if defined(__cpp_lib_char8_t) && (__cpp_lib_char8_t >= 201907L)
447447
const std::u8string s = p.u8string();
448448
j = std::string(s.begin(), s.end());
449449
#else

single_include/nlohmann/json.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5325,7 +5325,7 @@ inline void from_json(const BasicJsonType& j, std_fs::path& p)
53255325
JSON_THROW(type_error::create(302, concat("type must be string, but is ", j.type_name()), &j));
53265326
}
53275327
const auto& s = *j.template get_ptr<const typename BasicJsonType::string_t*>();
5328-
#ifdef JSON_HAS_CPP_20
5328+
#if defined(__cpp_lib_char8_t) && (__cpp_lib_char8_t >= 201907L)
53295329
p = std_fs::path(std::u8string_view(reinterpret_cast<const char8_t*>(s.data()), s.size()));
53305330
#else
53315331
p = std_fs::u8path(s); // accepts UTF-8 encoded std::string in C++17, deprecated in C++20
@@ -6090,7 +6090,7 @@ inline void to_json(BasicJsonType& j, const T& t)
60906090
template<typename BasicJsonType>
60916091
inline void to_json(BasicJsonType& j, const std_fs::path& p)
60926092
{
6093-
#ifdef JSON_HAS_CPP_20
6093+
#if defined(__cpp_lib_char8_t) && (__cpp_lib_char8_t >= 201907L)
60946094
const std::u8string s = p.u8string();
60956095
j = std::string(s.begin(), s.end());
60966096
#else

0 commit comments

Comments
 (0)