Skip to content

Bug: weak_ref::get() to an implementation type doesn't compile #1312

@sylveon

Description

@sylveon

Version

2.0.230225.1

Summary

When using a winrt::weak_ref::get() to some implementation type, a compiler error is thrown.

Reproducible example

#include <Unknwn.h>
#include <winrt/base.h>

struct __declspec(uuid("A9D68584-DB90-458E-BBA7-DB9537786276")) IFoo : IUnknown {};

struct foo : winrt::implements<foo, IFoo> {};

int main()
{
    winrt::weak_ref<foo> a;
    a.get();
}

Expected behavior

No compiler error

Actual behavior

1>C:\Projects\ConsoleApplication15\ConsoleApplication15\x64\Debug\Generated Files\winrt\base.h(6878,17): error C2440: 'static_cast': cannot convert from 'IFoo *' to 'winrt::impl::produce<T,winrt::com_ptr<IFoo>> *'
1>        with
1>        [
1>            T=foo
1>        ]
1>C:\Projects\ConsoleApplication15\ConsoleApplication15\x64\Debug\Generated Files\winrt\base.h(6878,17): message : Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or parenthesized function-style cast
1>C:\Projects\ConsoleApplication15\ConsoleApplication15\x64\Debug\Generated Files\winrt\base.h(4224,30): message : see reference to function template instantiation 'D *winrt::get_self<T,winrt::com_ptr<IFoo>>(const I &) noexcept' being compiled
1>        with
1>        [
1>            D=foo,
1>            T=foo,
1>            I=winrt::com_ptr<IFoo>
1>        ]
1>C:\Projects\ConsoleApplication15\ConsoleApplication15\x64\Debug\Generated Files\winrt\base.h(4211,28): message : while compiling class template member function 'winrt::com_ptr<D> winrt::weak_ref<D>::get(void) noexcept const'
1>        with
1>        [
1>            D=foo
1>        ]
1>C:\Projects\ConsoleApplication15\ConsoleApplication15\ConsoleApplication15.cpp(13,26): message : see reference to class template instantiation 'winrt::weak_ref<D>' being compiled
1>        with
1>        [
1>            D=foo
1>        ]

Additional comments

Works if I where to use a weak_ref<IFoo>, but I don't want that.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions