-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Parse to custom class from unordered_json breaks on G++11.2.0 with C++20 #3312
Comments
Can you try this:
|
@gregmarr the workaround works! Although I don't want to use the templated function, as I'd have to move all my |
Are you currently putting If you are doing that, you can just add a second version just like the first:
If you don't want to duplicate the whole body, you can do something like this:
@nlohmann Do we need to update the guides to tell people to use the templatized version if they're going to be using the other |
Yes, I think this was forgotten when |
so it was just a bug, that I was able to use it like that until now? (before C++20) |
@NeroBurner Not sure why it worked, there may have been some temporaries being created that probably aren't desired. @nlohmann It's not just |
that's unfortunate, but you're probably right. Thanks for the workarounds. Should I close issue, or do you want to keep it open until documentation is updated for people to find this open issue? |
I would leave it open for the docs. Thanks. |
Out of curiosity I did a
|
Constrain from_json() overload for ConstructibleStringType to not accept json_ref and require assignability. Re-enable C++14 tests on Clang <4.0. Fixes nlohmann#3171, nlohmann#3312, nlohmann#3384. Maybe fixes nlohmann#3267.
Constrain from_json() overload for ConstructibleStringType to not accept json_ref and require it to be assignable from basic_json::string_t. Re-enable C++14 tests on Clang <4.0. Fixes nlohmann#3171. Fixes nlohmann#3267. Fixes nlohmann#3312. Fixes nlohmann#3384.
Constrain from_json() overload for StringType to not accept json_ref and require it to be assignable, instead of constructible, from basic_json::string_t. Re-enable C++14 tests on Clang <4.0. Fixes nlohmann#3171. Fixes nlohmann#3267. Fixes nlohmann#3312. Fixes nlohmann#3384.
Awesome!! Thank you so much for fixing this. I thought it won't be fixed because it was unintentional behaviour and creates temporary copies of the Thank you! 🙇 |
What is the issue you have?
Parsing a custom class with a
std::string
member in it usingnlohmann::ordered_json
with C++20 starting with v3.10.4 results in a compilation error.Using v3.10.3 compiles fine
Probably related issue: #3207
Please describe the steps to reproduce the issue.
Godbolt link with example showing that g++ 11.2.0 fails to compile when C++20 is enabled
https://godbolt.org/z/MsYe45qP9
std::string
(custom class with just an int works)from_json
function for custom classordered_json
to class (normal unordered json works)Example code, which I'd like to add to unittests, but don't know where. (for the error message I added it to the bottom of
unit-deserialization.cpp
)Can you provide a small but working code example?
see above
What is the expected behavior?
Compile without error
And what is the actual behavior instead?
Compillation error:
Error message when compiling with Visual Studio 16 2019 in C++20 mode:
Which compiler and operating system are you using?
Also on Visual Studio 16 2019 in C++20 mode
Which version of the library did you use?
develop
branchIf you experience a compilation error: can you compile and run the unit tests?
edit: the unittest
test-comparison
fails in C++20 mode, as reported in issue: #3207The text was updated successfully, but these errors were encountered: