Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 28 additions & 10 deletions cppwinrt/code_writers.h
Original file line number Diff line number Diff line change
Expand Up @@ -2986,13 +2986,15 @@ struct __declspec(empty_bases) produce_dispatch_to_overridable<T, D, %>
return;
}

auto is_opt_type = settings.component_opt && settings.component_filter.includes(type);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is_component_type?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's "is optimized component type". non-optimized components still can use auto.


for (auto&& method : factory.second.type.MethodList())
{
method_signature signature{ method };
auto method_name = get_name(method);
auto async_types_guard = w.push_async_types(signature.is_async());

if (settings.component_opt && settings.component_filter.includes(type))
if (is_opt_type)
{
w.write(" %static % %(%);\n",
is_get_overload(method) ? "[[nodiscard]] " : "",
Expand All @@ -3010,17 +3012,33 @@ struct __declspec(empty_bases) produce_dispatch_to_overridable<T, D, %>

if (is_add_overload(method))
{
auto format = R"( using %_revoker = impl::factory_event_revoker<%, &impl::abi_t<%>::remove_%>;
[[nodiscard]] static auto %(auto_revoke_t, %);
{
auto format = R"( using %_revoker = impl::factory_event_revoker<%, &impl::abi_t<%>::remove_%>;
)";
w.write(format,
method_name,
factory.second.type,
factory.second.type,
method_name);
}

w.write(format,
method_name,
factory.second.type,
factory.second.type,
method_name,
method_name,
bind<write_consume_params>(signature));
if (is_opt_type)
{
auto format = R"( [[nodiscard]] static %_revoker %(auto_revoke_t, %);
)";
w.write(format,
method_name,
method_name,
bind<write_consume_params>(signature));
}
else
{
auto format = R"( [[nodiscard]] static auto %(auto_revoke_t, %);
)";
w.write(format,
method_name,
bind<write_consume_params>(signature));
}
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion cppwinrt/component_writers.h
Original file line number Diff line number Diff line change
Expand Up @@ -518,14 +518,16 @@ catch (...) { return winrt::to_hresult(); }

if (is_add_overload(method))
{
auto format = R"( auto %::%(auto_revoke_t, %)
auto format = R"( %::%_revoker %::%(auto_revoke_t, %)
{
auto f = make<winrt::@::factory_implementation::%>().as<%>();
return %::%_revoker{ f, f.%(%) };
}
)";

w.write(format,
type_name,
method_name,
type_name,
method_name,
bind<write_consume_params>(signature),
Expand Down
7 changes: 7 additions & 0 deletions test/test_component/Class.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -515,4 +515,11 @@ namespace winrt::test_component::implementation
}
return pass;
}
}

namespace
{
void ValidateStaticEventAutoRevoke() {
auto x = winrt::test_component::Simple::StaticEvent(winrt::auto_revoke, [](auto&&, auto&&) {});
}
}