C ++ / WinRT, часть Windows SDK 17134, не совместима с Visual Studio 15.8 Preview 3

Попытка скомпилировать следующий код:

#include <winrt/base.h>

int main() {}

Со следующими параметрами компилятора:

/permissive- /std:c++latest

С недавно выпущенным Visual Studio 15.8 Preview 3.0 возникают следующие ошибки компиляции:

1>------ Build started: Project: test1, Configuration: Debug x64 ------
1>Source.cpp
1>c:\program files (x86)\windows kits\10\include\10.0.17134.0\cppwinrt\winrt\base.h(2185): error C3861: 'from_abi': identifier not found
1>c:\program files (x86)\windows kits\10\include\10.0.17134.0\cppwinrt\winrt\base.h(2185): note: This diagnostic occurred in the compiler generated function 'conditional<_Test,T,_Ty2>::type winrt::impl::as(From *)'
1>        with
1>        [
1>            _Ty2=winrt::com_ptr<T>
1>        ]
1>c:\program files (x86)\windows kits\10\include\10.0.17134.0\cppwinrt\winrt\base.h(2209): error C3861: 'from_abi': identifier not found
1>c:\program files (x86)\windows kits\10\include\10.0.17134.0\cppwinrt\winrt\base.h(2209): note: This diagnostic occurred in the compiler generated function 'conditional<_Test,T,_Ty2>::type winrt::impl::try_as(From *) noexcept'
1>        with
1>        [
1>            _Ty2=winrt::com_ptr<T>
1>        ]
1>c:\program files (x86)\windows kits\10\include\10.0.17134.0\cppwinrt\winrt\base.h(3850): error C3861: 'from_abi': identifier not found
1>c:\program files (x86)\windows kits\10\include\10.0.17134.0\cppwinrt\winrt\base.h(3873): note: see reference to class template instantiation 'winrt::weak_ref<T>' being compiled
1>c:\program files (x86)\windows kits\10\include\10.0.17134.0\cppwinrt\winrt\base.h(2984): note: see reference to class template instantiation 'winrt::com_ptr<ILanguageExceptionErrorInfo2>' being compiled
1>c:\program files (x86)\windows kits\10\include\10.0.17134.0\cppwinrt\winrt\base.h(3054): note: see reference to class template instantiation 'winrt::com_ptr<IRestrictedErrorInfo>' being compiled
1>c:\program files (x86)\microsoft visual studio\preview\professional\vc\tools\msvc\14.15.26608\include\type_traits(616): note: see reference to class template instantiation 'std::basic_string_view<wchar_t,std::char_traits<wchar_t>>' being compiled
1>c:\program files (x86)\microsoft visual studio\preview\professional\vc\tools\msvc\14.15.26608\include\xstring(2124): note: see reference to class template instantiation 'std::is_convertible<const _StringViewIsh &,std::basic_string_view<wchar_t,std::char_traits<wchar_t>>>' being compiled
1>        with
1>        [
1>            _StringViewIsh=const wchar_t *
1>        ]
1>c:\program files (x86)\microsoft visual studio\preview\professional\vc\tools\msvc\14.15.26608\include\xstring(2122): note: see reference to variable template 'const bool conjunction_v<std::is_convertible<wchar_t const * const &,std::basic_string_view<wchar_t,std::char_traits<wchar_t> > >,std::negation<std::is_convertible<wchar_t const * const &,wchar_t const *> > >' being compiled
1>c:\program files (x86)\microsoft visual studio\preview\professional\vc\tools\msvc\14.15.26608\include\xstring(2281): note: see reference to alias template instantiation '_Is_string_view_ish<const wchar_t*>' being compiled
1>c:\program files (x86)\windows kits\10\include\10.0.17134.0\cppwinrt\winrt\base.h(6308): error C3861: 'to_abi': identifier not found
1>Done building project "test1.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Есть ли решение?

8

Решение

Это известная проблема, которая будет устранена в будущем обновлении SDK для Windows 10.

Вы можете обойти это, либо полностью отключив режим соответствия (/permissive-), или оставить его, добавив к Дополнительные опции /Zc:twoPhase- отключить поиск по двухфазному имени.

Вы должны использовать /std:c++17 и не /std:c++latest с VS 2017 для C ++ / WinRT для включения C ++ 17 без участия в будущих черновых изменениях.

ОБНОВИТЬ: Эта проблема решена с помощью Windows 10 октября 2018 SDK обновления (17763).

12

Другие решения

Я сделал небольшой патч, чтобы исправить эту проблему. Он добавляет пару предварительных объявлений, чтобы можно было найти необходимые имена с двухфазным поиском и отсутствующим template ключевое слово.

C: \ Program Files (x86) \ Windows Kits \ 10 \ Include \ 10.0.17134.0 \ cppwinrt \ winrt \ base.h

2171a2172,2189
>     template <typename D, typename I, typename Enable = void>
>     struct producer;
> }
>
> WINRT_EXPORT namespace winrt
> {
>     template <typename D, typename I>
>     D* from_abi(I const& from) noexcept;
>
>   template <typename I, typename D, std::enable_if_t<std::is_base_of_v<Windows::Foundation::IUnknown, I>>* = nullptr>
>     impl::abi_t<I>* to_abi(impl::producer<D, I> const* from) noexcept;
>
>     template <typename I, typename D, std::enable_if_t<std::is_base_of_v< ::IUnknown, I>>* = nullptr>
>     impl::abi_t<I>* to_abi(impl::producer<D, I> const* from) noexcept;
> }
>
> namespace winrt::impl
> {
6244c6262
<     template <typename D, typename I, typename Enable = void>
---
>     template <typename D, typename I, typename Enable>
6353c6371
<     template <typename I, typename D, std::enable_if_t<std::is_base_of_v<Windows::Foundation::IUnknown, I>>* = nullptr>
---
>     template <typename I, typename D, std::enable_if_t<std::is_base_of_v<Windows::Foundation::IUnknown, I>>*>
6359c6377
<     template <typename I, typename D, std::enable_if_t<std::is_base_of_v< ::IUnknown, I>>* = nullptr>
---
>     template <typename I, typename D, std::enable_if_t<std::is_base_of_v< ::IUnknown, I>>*>
7189c7207
<             return root_implements_type::get_weak<D>();
---
>             return root_implements_type::template get_weak<D>();
0