From 5ad4a1eabe5292c191c0cd0dc458572f4654f905 Mon Sep 17 00:00:00 2001 From: YexuanXiao Date: Sun, 5 Apr 2026 18:56:49 +0800 Subject: [PATCH] Add [[nodiscard]] to overloads of static events that return winrt::event_token --- cppwinrt/code_writers.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/cppwinrt/code_writers.h b/cppwinrt/code_writers.h index 0ab93b334..65cc48b9c 100644 --- a/cppwinrt/code_writers.h +++ b/cppwinrt/code_writers.h @@ -3163,10 +3163,12 @@ struct WINRT_IMPL_EMPTY_BASES produce_dispatch_to_overridable auto method_name = get_name(method); auto async_types_guard = w.push_async_types(signature.is_async()); + auto is_event = is_add_overload(method); + if (is_opt_type) { w.write(" %static % %(%);\n", - is_get_overload(method) ? "[[nodiscard]] " : "", + is_get_overload(method) || is_event ? "[[nodiscard]] " : "", signature.return_signature(), method_name, bind(signature)); @@ -3174,12 +3176,12 @@ struct WINRT_IMPL_EMPTY_BASES produce_dispatch_to_overridable else { w.write(" %static auto %(%);\n", - is_get_overload(method) ? "[[nodiscard]] " : "", + is_get_overload(method) || is_event ? "[[nodiscard]] " : "", method_name, bind(signature)); } - if (is_add_overload(method)) + if (is_event) { { auto format = R"( using %_revoker = impl::factory_event_revoker<%, &impl::abi_t<%>::remove_%>;