Skip to content

Bug: clang - impl type cannot convert to projected type #1273

Description

Version

2.0.230207.1 and earlier (tested 2.0.210825.3)

Summary

No response

Reproducible example

#include <winrt/Windows.Foundation.h>
#include <winrt/Windows.Foundation.Collections.h>

struct Stringy : public winrt::implements<Stringy, winrt::Windows::Foundation::IStringable> {
	Stringy() {}
	winrt::hstring ToString() {
		return L"FooBarBaz";
	}
};

int main()
{
	winrt::init_apartment();
	auto x = winrt::make_self<Stringy>();
	winrt::Windows::Foundation::IStringable broken{ *x };
	printf("Hello, %ls!\n", broken.ToString().c_str());
}

Expected behavior

works, works.

Actual behavior

Something is preventing the following conversion from taking place:

Stringy
 +--> producer_convert::operator producer_ref<IStringable>
       +--> IStringable

resulting in the following chain of error messages

1>main.cpp(18,50): error : no viable conversion from 'Stringy' to 'winrt::Windows::Foundation::IStringable'
1>C:\src\ClangCppWinRTTest1\x64\Debug\Generated Files\winrt\impl\Windows.Foundation.1.h(170,35): message : candidate constructor (the implicit copy constructor) not viable: no known conversion from 'Stringy' to 'const winrt::Windows::Foundation::IStringable &' for 1st argument
1>C:\src\ClangCppWinRTTest1\x64\Debug\Generated Files\winrt\impl\Windows.Foundation.1.h(170,35): message : candidate constructor (the implicit move constructor) not viable: no known conversion from 'Stringy' to 'winrt::Windows::Foundation::IStringable &&' for 1st argument
1>C:\src\ClangCppWinRTTest1\x64\Debug\Generated Files\winrt\impl\Windows.Foundation.1.h(174,9): message : candidate constructor not viable: no known conversion from 'Stringy' to 'std::nullptr_t' for 1st argument
1>C:\src\ClangCppWinRTTest1\x64\Debug\Generated Files\winrt\base.h(8095,9): message : candidate function
1>C:\src\ClangCppWinRTTest1\x64\Debug\Generated Files\winrt\base.h(6749,9): message : candidate function
1>C:\src\ClangCppWinRTTest1\x64\Debug\Generated Files\winrt\base.h(6754,9): message : candidate function
1>C:\src\ClangCppWinRTTest1\x64\Debug\Generated Files\winrt\impl\Windows.Foundation.1.h(170,35): message : passing argument to parameter here

Additional comments

If you write out the (verbose, impl types) conversion from Stringy to producer_ref<IStringable> explicitly, it works properly with no warning/error; n.b. the static_cast is using operator producer_ref<I>.

winrt::Windows::Foundation::IStringable works{
    static_cast<winrt::impl::producer_ref<winrt::Windows::Foundation::IStringable>>(*x)
};

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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