microsoft / cppwinrt

C++/WinRT
MIT License
1.65k stars 238 forks source link

Bug: Weird c++20 MainWindow.xaml.g.hpp bug #1421

Closed tom-huntington closed 3 months ago

tom-huntington commented 3 months ago

Version

2.0.230706.1

Summary

The Xaml compiler generates code that calls winrt::Windows::Foundation::IReference<bool>::Value https://github.com/microsoft/microsoft-ui-xaml/issues/9214.

If you force the instantiation of winrt::Windows::Foundation::IReference<bool>::Value there is no problem.

Otherwise, you get the classic a function that returns 'auto' cannot be used before it is defined error even though the header is properly included.

Feel free to close it seems like a msvc bug since in only happens on /std:c++20, I just though you might want to know.

Reproducible example

https://github.com/tom-huntington/auto-bool-visibility-conversion-cpp20-regression

//MainWindow.xaml.h
#if 1
inline void force_instantiation_of_IRefBoolValue()
{
    &winrt::Windows::Foundation::IReference<bool>::Value;
}
#else
//error C3779 : 'winrt::impl::consume_Windows_Foundation_IReference<winrt::Windows::Foundation::IReference<bool>,T>::Value' : a function that returns 'auto' cannot be used before it is defined
#endif
kennykerr commented 3 months ago

Thanks, if you think this is a compiler bug your best bet is to report a problem here:

https://developercommunity.visualstudio.com/cpp

For Xaml-related issues you're better off engaging directly with the Xaml team here:

https://github.com/microsoft/microsoft-ui-xaml