microsoft / cppwinrt

C++/WinRT
MIT License
1.66k stars 239 forks source link

Bug: Incorrect alias template for derived class impl base #1320

Closed JaiganeshKumaran closed 1 year ago

JaiganeshKumaran commented 1 year ago

Version

2.0.230524.4

Summary

I have a derived class that derives from a composable base class. In this case, RuntimeClass_base has two required template parameters (D for the derived, and B for the implementation base). However, the alias it writes RuntimeClassT only takes D as a required template parameter.

Reproducible example

// IDL
namespace OneToolkit.UI.Media
{
    [default_interface]
    unsealed runtimeclass AttachedShadowBase : XAML.DependencyObject;

    runtimeclass AttachedDropShadow : AttachedShadowBase;
}

// AttachedDropShadow.g.h
namespace winrt::OneToolkit::UI::Media::implementation
{
    template <typename D, typename B, typename... I>
    struct WINRT_IMPL_EMPTY_BASES AttachedDropShadow_base : implements<D, OneToolkit::UI::Media::AttachedDropShadow, B, no_module_lock, I...>;

    // later
    template <typename D, typename... I>
    using AttachedDropShadowT = AttachedDropShadow_base<D, I...>;
}

Expected behavior

AttachedDropShadowT should have a B parameter.

Actual behavior

AttachedDropShadowT only has D and (variadic) I template parameters.

Additional comments

No response

sylveon commented 1 year ago

Adding B as a separate template parameter would make it required, however in the case you're composing a class that's external to your code (such is the case in XAML), you do not have access to the implementation class for the base, so you wouldn't be able to pass it as B. I... does end up providing B when you do need to pass it, so it isn't really an issue.

JaiganeshKumaran commented 1 year ago

@sylveon Don't I need to pass AttachedShadowBase as B to AttachedDropShadow?

sylveon commented 1 year ago

Yes, and you can still do that even with just I...