Provide fallback for missing char8_t support#4736
Conversation
f77af2b to
a66c329
Compare
a66c329 to
69c3fd0
Compare
| { | ||
| #ifdef JSON_HAS_CPP_20 | ||
| const std::u8string s = p.u8string(); | ||
| const auto& s = p.u8string(); |
There was a problem hiding this comment.
Removing the conditional compilation adds an unnecessary copy to those using it in C++17.
There was a problem hiding this comment.
Unfortunately, without this change the tests fail because BasicJsonType::is_string no longer holds in corresponding from_json.
There was a problem hiding this comment.
Testing against 201811L seems to solve the issue. However, compilation using Clang 11.0.x starts failing again.
There was a problem hiding this comment.
@sergiud Oh, that's annoying. So, libc++ in Clang 11.0.x sets __cpp_lib_char8_t 201811L but doesn't actually implement p.u8string() returning std::u8string until it's set to 201907L?
That's ugly.
However, this still means that everything using C++17 has to pay for this copy unnecessarily, where they didn't before. Would the following work?
const auto& s = p.u8string();
#if defined(__cpp_lib_char8_t) && (__cpp_lib_char8_t >= 201907L)
j = std::string(s.begin(), s.end());
#else
j = s; // returns std::string in C++17
#endif
There was a problem hiding this comment.
Yes, __cpp_lib_char8_t version is somewhat unreliable. Therefore, instead of feature testing against a specific version for char8_t library support a better approach is probably to provide a std::u8string overload whenever __cpp_lib_char8_t is defined.
69c3fd0 to
161f0de
Compare
161f0de to
8fb2005
Compare
|
Would it make sense to extend the CI to run the Clang tests additionally with |
|
The Given GCC 14 (using libstdc++) suffers from a related issue, reproducing the setup for the latter is probably also sensible going forward. |
Yes, these jobs use the latest Clang version. Question is if it makes sense to also do this with (some/all) of the other Clang versions we use in
Not sure what additional setup is used there. We already use GCC 14 in the CI. Maybe @jelly can help? |
8fb2005 to
68a0a01
Compare
|
According to #4733 (comment) it's |
68a0a01 to
955d205
Compare
🔴 Amalgamation check failed! 🔴The source code has not been amalgamated. @sergiud |
955d205 to
19687e7
Compare
c26c38a to
1d11ec1
Compare
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>
1d11ec1 to
6c4cf7a
Compare
🔴 Amalgamation check failed! 🔴The source code has not been amalgamated. @sergiud |
3d089b2 to
34868f9
Compare
|
I've no idea what Codacy's problem is. |
I think we can ignore it. |
|
I suppressed the issue in Codacy. |
|
@gregmarr Any further comments or is this ready to merge? |
One test breaks because OpenBSD doesn't support LC_NUMERIC. Pull in an upstream fix for incorrect char8_t support with C++20 to unbreak the build of games/openrtc2 https://github.com/nlohmann/json/releases/tag/v3.11.3 https://github.com/nlohmann/json/releases/tag/v3.12.0 nlohmann/json#4736
|
Hi, my project can't update to json 3.12.0, because we build with char8_t disabled. Is there appetite for cutting a new release with this fix included, possibly as a 3.12.1 ? |
Clang 11.0.x with libc++ fails to compile tests in C++20 mode due to incomplete
char8_tsupport instd::filesystem::path. Use a specific library feature guard instead of performing a generic C++20 language standard check.Fixes #4733
make amalgamate.Read the Contribution Guidelines for detailed information.