Repository navigation
Define json::value's unique_ptr constructor and destructor out of line - #36
Merged
Merged
Conversation
json.h defines the private constructor that takes a std::unique_ptr<details::_Value> inline, and the destructor is implicit, so both destroy the unique_ptr where _Value is incomplete. From C++23, std::unique_ptr's destructor is constexpr, and Clang 21 instantiates it there, so std::default_delete's static_assert fails in every translation unit that includes cpprest/json.h. Declare the constructor and the destructor in json.h, and define them in json.cpp, where _Value is complete. Taken from vcpkg's ports/cpprestsdk/fix-incomplete-json-value.patch, added in microsoft/vcpkg@d015e31e90 (microsoft/vcpkg#51307). The destructor is declared with the other public special members, rather than in a public section among the private members. Part of #13. Signed-off-by: Gareth Sylvester-Bradley <garethsb@nvidia.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
cpprest/json.hdefines the privatejson::valueconstructor that takes astd::unique_ptr<details::_Value>inline, and the destructor is implicit. Both destroy theunique_ptrwhere_Valueis incomplete. From C++23,std::unique_ptr's destructor isconstexpr, and Clang 21 instantiates it there, sostd::default_delete'sstatic_assertfails in every translation unit that includescpprest/json.h.This PR declares the constructor and the destructor in
json.hand defines them injson.cpp, where_Valueis complete. The change is taken from vcpkg'sports/cpprestsdk/fix-incomplete-json-value.patch, added by Nicholas Matteo in microsoft/vcpkg#51307, and keeps him as the commit author. The one difference from the patch is where the destructor is declared: here it is with the other public special members, not in apublic:block among the private members.json::valuealready declares its copy and move operations, so declaring the destructor leaves them unchanged.Testing
I tested with Clang 21.1.8 on Ubuntu 26.04:
cpprest/json.hfails at-std=c++23without this change, with both libstdc++ 15 and libc++ 21. It compiles with this change at C++17, C++20 and C++23.-DCMAKE_CXX_STANDARD=23, the library build fails without this change and succeeds with it. The library's CMake adds-std=c++11, so only a consumer's C++23 setting triggers the error.Not Included
Issue #13 also asks for a CI job with a recent Clang, so this PR doesn't close it. A C++23 job can't build the tests yet, because three test files don't compile at C++20 or later:
test_runner.cppusesrequiresas a variable name, andrequiresis a keyword from C++20.strings.cppandmemstream_tests.cppwritechar16_tvalues to a stream through UnitTest++, and C++20 deletes those stream operators.Part of #13.
Co-authored-by: Gareth's 🤖 buddy