From 858988bbd908398c5fac0562694d1bf28ae8492c Mon Sep 17 00:00:00 2001 From: Raymond Chen Date: Thu, 14 Apr 2022 17:57:46 -0700 Subject: [PATCH 1/2] Use `auto` trick to catch missing header files for auto_revoke We forgot to apply the `auto` trick to catch missing header files at compile time. As a result, people who used `auto_revoke` didn't learn about missing header files until link time. Apply the same technique to auto-revoke event handler registeration. (Story time: A customer was running into linker errors due to a missing header file when they used `auto_revoke`. One thing they tried was switching to non-`auto_revoke` events, and then they got the compile-time error. But their conclusion wasn't "Oh, there's my problem" but rather "That made it worse, go back!") --- cppwinrt/code_writers.h | 14 ++++++++------ cppwinrt/component_writers.h | 6 ++++-- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/cppwinrt/code_writers.h b/cppwinrt/code_writers.h index adf9a1392..8284b95b8 100644 --- a/cppwinrt/code_writers.h +++ b/cppwinrt/code_writers.h @@ -1001,7 +1001,7 @@ namespace cppwinrt if (is_add_overload(method)) { auto format = R"( using %_revoker = impl::event_revoker<%, &impl::abi_t<%>::remove_%>; - [[nodiscard]] %_revoker %(auto_revoke_t, %) const; + [[nodiscard]] WINRT_IMPL_AUTO(%_revoker) %(auto_revoke_t, %) const; )"; w.write(format, @@ -1170,7 +1170,7 @@ namespace cppwinrt if (is_add_overload(method)) { - format = R"( template typename consume_%::%_revoker consume_%::%(auto_revoke_t, %) const + format = R"( template WINRT_IMPL_AUTO(typename consume_%::%_revoker) consume_%::%(auto_revoke_t, %) const { return impl::make_event_revoker(this, %(%)); } @@ -1214,7 +1214,7 @@ namespace cppwinrt if (is_add_overload(method)) { - format = R"( inline %::%_revoker %::%(auto_revoke_t, %) const + format = R"( inline WINRT_IMPL_AUTO(%::%_revoker) %::%(auto_revoke_t, %) const { return impl::make_event_revoker(this, %(%)); } @@ -3017,7 +3017,7 @@ struct __declspec(empty_bases) produce_dispatch_to_overridable if (is_add_overload(method)) { auto format = R"( using %_revoker = impl::factory_event_revoker<%, &impl::abi_t<%>::remove_%>; - [[nodiscard]] static %_revoker %(auto_revoke_t, %); + [[nodiscard]] static WINRT_IMPL_AUTO(%_revoker) %(auto_revoke_t, %); )"; w.write(format, @@ -3056,10 +3056,10 @@ struct __declspec(empty_bases) produce_dispatch_to_overridable if (is_add_overload(method)) { - auto format = R"( inline %::%_revoker %::%(auto_revoke_t, %) + auto format = R"( inline WINRT_IMPL_AUTO(%::%_revoker) %::%(auto_revoke_t, %) { auto f = get_activation_factory<%, %>(); - return { f, f.%(%) }; + return %::%_revoker{ f, f.%(%) }; } )"; @@ -3071,6 +3071,8 @@ struct __declspec(empty_bases) produce_dispatch_to_overridable bind(signature), type_name, factory, + type_name, + method_name, method_name, bind(signature)); } diff --git a/cppwinrt/component_writers.h b/cppwinrt/component_writers.h index fcb9f5ac7..f84c701f9 100644 --- a/cppwinrt/component_writers.h +++ b/cppwinrt/component_writers.h @@ -518,10 +518,10 @@ catch (...) { return winrt::to_hresult(); } if (is_add_overload(method)) { - auto format = R"( %::%_revoker %::%(auto_revoke_t, %) + auto format = R"( WINRT_IMPL_AUTO(%::%_revoker) %::%(auto_revoke_t, %) { auto f = make().as<%>(); - return { f, f.%(%) }; + return %::%_revoker{ f, f.%(%) }; } )"; @@ -534,6 +534,8 @@ catch (...) { return winrt::to_hresult(); } type_namespace, type_name, factory_name, + type_name, + method_name, method_name, bind(signature)); } From 3e0382dffcb65505264c7c5c13d07476ec8d050d Mon Sep 17 00:00:00 2001 From: Raymond Chen Date: Wed, 20 Apr 2022 15:03:48 -0700 Subject: [PATCH 2/2] Sync up with death of WINRT_IMPL_AUTO --- cppwinrt/code_writers.h | 19 +++++-------------- cppwinrt/component_writers.h | 4 +--- 2 files changed, 6 insertions(+), 17 deletions(-) diff --git a/cppwinrt/code_writers.h b/cppwinrt/code_writers.h index 8284b95b8..7122e9541 100644 --- a/cppwinrt/code_writers.h +++ b/cppwinrt/code_writers.h @@ -1001,7 +1001,7 @@ namespace cppwinrt if (is_add_overload(method)) { auto format = R"( using %_revoker = impl::event_revoker<%, &impl::abi_t<%>::remove_%>; - [[nodiscard]] WINRT_IMPL_AUTO(%_revoker) %(auto_revoke_t, %) const; + [[nodiscard]] auto %(auto_revoke_t, %) const; )"; w.write(format, @@ -1010,7 +1010,6 @@ namespace cppwinrt type, method_name, method_name, - method_name, bind(signature)); } } @@ -1170,7 +1169,7 @@ namespace cppwinrt if (is_add_overload(method)) { - format = R"( template WINRT_IMPL_AUTO(typename consume_%::%_revoker) consume_%::%(auto_revoke_t, %) const + format = R"( template auto consume_%::%(auto_revoke_t, %) const { return impl::make_event_revoker(this, %(%)); } @@ -1181,9 +1180,6 @@ namespace cppwinrt type_impl_name, bind(generics), method_name, - type_impl_name, - bind(generics), - method_name, bind(signature), method_name, method_name, @@ -1214,15 +1210,13 @@ namespace cppwinrt if (is_add_overload(method)) { - format = R"( inline WINRT_IMPL_AUTO(%::%_revoker) %::%(auto_revoke_t, %) const + format = R"( inline auto %::%(auto_revoke_t, %) const { return impl::make_event_revoker(this, %(%)); } )"; w.write(format, - class_type.TypeName(), - method_name, class_type.TypeName(), method_name, bind(signature), @@ -3017,7 +3011,7 @@ struct __declspec(empty_bases) produce_dispatch_to_overridable if (is_add_overload(method)) { auto format = R"( using %_revoker = impl::factory_event_revoker<%, &impl::abi_t<%>::remove_%>; - [[nodiscard]] static WINRT_IMPL_AUTO(%_revoker) %(auto_revoke_t, %); + [[nodiscard]] static auto %(auto_revoke_t, %); )"; w.write(format, @@ -3026,7 +3020,6 @@ struct __declspec(empty_bases) produce_dispatch_to_overridable factory.second.type, method_name, method_name, - method_name, bind(signature)); } } @@ -3056,7 +3049,7 @@ struct __declspec(empty_bases) produce_dispatch_to_overridable if (is_add_overload(method)) { - auto format = R"( inline WINRT_IMPL_AUTO(%::%_revoker) %::%(auto_revoke_t, %) + auto format = R"( inline auto %::%(auto_revoke_t, %) { auto f = get_activation_factory<%, %>(); return %::%_revoker{ f, f.%(%) }; @@ -3064,8 +3057,6 @@ struct __declspec(empty_bases) produce_dispatch_to_overridable )"; w.write(format, - type_name, - method_name, type_name, method_name, bind(signature), diff --git a/cppwinrt/component_writers.h b/cppwinrt/component_writers.h index f84c701f9..98bc75720 100644 --- a/cppwinrt/component_writers.h +++ b/cppwinrt/component_writers.h @@ -518,7 +518,7 @@ catch (...) { return winrt::to_hresult(); } if (is_add_overload(method)) { - auto format = R"( WINRT_IMPL_AUTO(%::%_revoker) %::%(auto_revoke_t, %) + auto format = R"( auto %::%(auto_revoke_t, %) { auto f = make().as<%>(); return %::%_revoker{ f, f.%(%) }; @@ -526,8 +526,6 @@ catch (...) { return winrt::to_hresult(); } )"; w.write(format, - type_name, - method_name, type_name, method_name, bind(signature),