Skip to content

Build and test with Clang at C++20 and C++23 - #37

Merged
garethsb merged 4 commits into
cpprest-ltsfrom
fix/cxx20-tests
Nov 5, 2026
Merged

garethsb merged 4 commits into
cpprest-ltsfrom
fix/cxx20-tests

Conversation

@garethsb

@garethsb garethsb commented Nov 5, 2026

Copy link
Copy Markdown
Collaborator

#36 fixed cpprest/json.h for C++23. Clang 21 still gave about 680 warnings about implicit this capture 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.

  • Capture this explicitly 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 adds CPPREST_CAPTURE_THIS, which expands to , this from C++20, for use as [= CPPREST_CAPTURE_THIS]. Before C++20, [=, this] is ill-formed, and from C++20, [=] capturing this implicitly is deprecated. Two merge conflicts in http_server_asio.cpp came from the Boost 1.87 port's buffer_cast changes, and I resolved them by keeping both changes.
  • Define the macro where pplxtasks.h can see it. The cherry-picked commit defines the macros in basic_types.h, which pplxtasks.h doesn't include, so the pplx and streams tests failed to compile. This commit moves them to cpprest_compat.h, which both headers include. The lambda in pplxtasks.h uses only this, so it now uses [this], which is valid from C++11.
  • Build the tests at C++20 and later. test_runner.cpp used requires as a variable name, and requires is a keyword from C++20. C++20 also deletes operator<< for writing char16_t to 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 uses decltype, so a deleted operator counts as unsupported.
  • Add a CI job. It runs on Ubuntu 26.04 and builds and tests with Clang at C++23, in Debug and Release.

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 deprecated volatile increment in pplxtask_tests.cpp.

Fixes #13.

Co-authored-by: Gareth's 🤖 buddy

vadz and others added 4 commits November 5, 2026 10:18
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
garethsb merged commit 3985507 into cpprest-lts Nov 5, 2026
15 of 16 checks passed
@garethsb
garethsb deleted the fix/cxx20-tests branch November 5, 2026 10:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Build fails with Clang 21: json.h destroys a std::unique_ptr to an incomplete type

2 participants