Skip to content

Commit

Permalink
Use std:: coroutines for compatibility with C++20 and Clang 17 (#12887)
Browse files Browse the repository at this point in the history
* Use std:: coroutines for compatibility with C++20 and Clang 17

Newer versions of Clang do not support mixing C++20 and std::experimental coroutines. In such cases, we should prefer the coroutine types declared in the std:: namespace. Fortunately, there is already a helper namespace for this in winrt/base.h.

* Change files

* yarn format
  • Loading branch information
rozele committed Mar 28, 2024
1 parent d6748d2 commit 0385d90
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "Use std:: coroutines for compatibility with C++20 and Clang 17",
"packageName": "react-native-windows",
"email": "ericroz@meta.com",
"dependentChangeType": "patch"
}
4 changes: 2 additions & 2 deletions vnext/Shared/Networking/WinRTWebSocketResource.cpp
Expand Up @@ -64,9 +64,9 @@ auto resume_in_queue(const Mso::DispatchQueue &queue) noexcept {

void await_resume() const noexcept {}

void await_suspend(std::experimental::coroutine_handle<> resume) noexcept {
void await_suspend(winrt::impl::coroutine_handle<> resume) noexcept {
m_callback = [context = resume.address()]() noexcept {
std::experimental::coroutine_handle<>::from_address(context)();
winrt::impl::coroutine_handle<>::from_address(context)();
};
m_queue.Post(std::move(m_callback));
}
Expand Down
4 changes: 2 additions & 2 deletions vnext/Shared/Utils/CppWinrtLessExceptions.h
Expand Up @@ -35,15 +35,15 @@ struct lessthrow_await_adapter {
return async.Status() == winrt::Windows::Foundation::AsyncStatus::Completed;
}

void await_suspend(std::experimental::coroutine_handle<> handle) const {
void await_suspend(winrt::impl::coroutine_handle<> handle) const {
auto context = winrt::capture<winrt::impl::IContextCallback>(WINRT_IMPL_CoGetObjectContext);

async.Completed([handle, context = std::move(context)](auto const &, winrt::Windows::Foundation::AsyncStatus) {
winrt::impl::com_callback_args args{};
args.data = handle.address();

auto callback = [](winrt::impl::com_callback_args *args) noexcept -> int32_t {
std::experimental::coroutine_handle<>::from_address(args->data)();
winrt::impl::coroutine_handle<>::from_address(args->data)();
return S_OK;
};

Expand Down

0 comments on commit 0385d90

Please sign in to comment.