From fce2d412476cb07a5740a0e4a24af83dfebb5ab2 Mon Sep 17 00:00:00 2001 From: YexuanXiao Date: Thu, 5 Nov 2026 12:28:43 +0800 Subject: [PATCH] Avoid using intrinsics in Windows.Foundation.ixx --- strings/base_coroutine_foundation.h | 7 +++++++ test/test_cpp20_module/coroutines.cpp | 8 ++++++++ 2 files changed, 15 insertions(+) diff --git a/strings/base_coroutine_foundation.h b/strings/base_coroutine_foundation.h index 82582ee64..dd88bb4ad 100644 --- a/strings/base_coroutine_foundation.h +++ b/strings/base_coroutine_foundation.h @@ -895,7 +895,14 @@ WINRT_EXPORT namespace winrt { auto sender_abi = *(impl::unknown_abi**)&sender; + +#if defined(__cpp_lib_atomic_ref) && __cpp_lib_atomic_ref >= 201806L + void* expected = nullptr; + std::atomic_ref ref{ *reinterpret_cast(&result) }; + if (ref.compare_exchange_strong(expected, static_cast(sender_abi))) +#else if (nullptr == _InterlockedCompareExchangePointer(reinterpret_cast(&result), sender_abi, nullptr)) +#endif { sender_abi->AddRef(); status = operation_status; diff --git a/test/test_cpp20_module/coroutines.cpp b/test/test_cpp20_module/coroutines.cpp index 1553b1c6d..4b4b8ac8c 100644 --- a/test/test_cpp20_module/coroutines.cpp +++ b/test/test_cpp20_module/coroutines.cpp @@ -56,3 +56,11 @@ TEST_CASE("module_async_cancel") op.Cancel(); REQUIRE(op.Status() == AsyncStatus::Canceled); } + +TEST_CASE("module_async_when_any") +{ + auto a = do_nothing_async(); + auto b = do_nothing_async(); + auto c = winrt::when_any(a, b); + c.get(); +}