Subtle C++/WinRT Invoke Issue and its Fix
2025-03-09

A C++/WinRT pull request fixed an ambiguity in `winrt::impl::promise_base::set_completed`'s call to `invoke`, caused by Argument-dependent Lookup (ADL). The upgrade to C++20 coroutines expanded the ADL search space, unexpectedly finding `std::invoke` instead of the intended `winrt::impl::invoke`. The article details the ADL mechanism and provides a patch for older C++/WinRT versions: declaring a better-matching `invoke` function in the `winrt::Windows::Foundation` namespace to guide the compiler. This patch also includes a static assertion to ensure it's automatically removed after upgrading C++/WinRT.
Development