Repository navigation
Build and test with Clang at C++20 and C++23 - #37
Merged
Merged
Conversation
Capture "this" explicitly when using C++20, while still not doing it for the earlier versions of the language as it is explicitly not allowed in C++17. (cherry picked from commit 4e8ac12, microsoft#1827) Signed-off-by: Gareth Sylvester-Bradley <garethsb@nvidia.com>
pplxtasks.h does not include basic_types.h, which defined CPPREST_CHECK_CXX_STD and CPPREST_CAPTURE_THIS, so code that includes pplxtasks.h without basic_types.h, such as the pplx and streams tests, fails to compile. Define the macros in cpprest_compat.h, which both headers include. The lambda in pplxtasks.h uses only this, so capture it with [this], which is valid from C++11. Signed-off-by: Gareth Sylvester-Bradley <garethsb@nvidia.com>
From C++20, requires is a keyword, so rename the variable in test_runner.cpp. C++20 also deletes operator<< for writing char16_t to a narrow stream. UnitTest++ detects whether a failure message can show the values with a pre-C++11 overload trick, which selects the deleted operator and fails to compile; detect it with decltype instead, so that a deleted operator counts as unsupported. Signed-off-by: Gareth Sylvester-Bradley <garethsb@nvidia.com>
Add a job on Ubuntu 26.04 that builds with Clang at C++23, in Debug and Release, so that the library, its headers and the tests keep building with a recent Clang and C++ standard. Fixes #13. Signed-off-by: Gareth Sylvester-Bradley <garethsb@nvidia.com>
garethsb
force-pushed
the
fix/cxx20-tests
branch
from
November 5, 2026 10:20
dd448b2 to
e5b525d
Compare
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.
#36 fixed
cpprest/json.hfor C++23. Clang 21 still gave about 680 warnings about implicitthiscapture at C++20 and later, many of them from public headers. Three test files also failed to compile at C++20 and later. This PR fixes both and adds a CI job that builds and tests with Clang at C++23.thisexplicitly from C++20. This is Vadim Zeitlin's commit from Fix errors about implicit "this" capture in C++20 mode microsoft/cpprestsdk#1827, cherry-picked with him as the author. It addsCPPREST_CAPTURE_THIS, which expands to, thisfrom C++20, for use as[= CPPREST_CAPTURE_THIS]. Before C++20,[=, this]is ill-formed, and from C++20,[=]capturingthisimplicitly is deprecated. Two merge conflicts inhttp_server_asio.cppcame from the Boost 1.87 port'sbuffer_castchanges, and I resolved them by keeping both changes.pplxtasks.hcan see it. The cherry-picked commit defines the macros inbasic_types.h, whichpplxtasks.hdoesn't include, so the pplx and streams tests failed to compile. This commit moves them tocpprest_compat.h, which both headers include. The lambda inpplxtasks.huses onlythis, so it now uses[this], which is valid from C++11.test_runner.cppusedrequiresas a variable name, andrequiresis a keyword from C++20. C++20 also deletesoperator<<for writingchar16_tto a narrow stream. UnitTest++ checked whether a failure message can show the values with a pre-C++11 overload trick, and that check failed to compile when it selected the deleted operator. It now usesdecltype, so a deleted operator counts as unsupported.Testing
I tested with Clang 21.1.8 and libstdc++ 15 on Ubuntu 26.04. Debug builds at C++20 and C++23 pass all 7 test suites, with WebSockets excluded. A C++23 Release build with WebSockets, using Ubuntu's websocketpp package, also passes all 7. Four warnings remain, all in test files: three from implicit conversions in
json_numbers_tests.cpp, and one from a deprecatedvolatileincrement inpplxtask_tests.cpp.Fixes #13.
Co-authored-by: Gareth's 🤖 buddy