Skip to content

Commit

Permalink
Make guid constexpr on Clang and improve error reporting (#1191)
Browse files Browse the repository at this point in the history
  • Loading branch information
sylveon authored Sep 29, 2022
1 parent 64cdc7c commit e7b6903
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 39 deletions.
9 changes: 6 additions & 3 deletions Directory.Build.Props
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@
-->

<PropertyGroup Condition="'$(Clang)'=='1'">
<CLToolExe>clang-cl.exe</CLToolExe>
<CLToolPath>C:\Program Files\LLVM\bin</CLToolPath>
<PlatformToolset>ClangCL</PlatformToolset>
<!-- The experimental coroutines aren't supported under Clang -->
<CppWinRTLanguageStandard>20</CppWinRTLanguageStandard>
<!-- Disable vcpkg autolink because it's not compatible with lld-link -->
<VcpkgAutoLink>false</VcpkgAutoLink>
</PropertyGroup>

<PropertyGroup>
Expand All @@ -51,7 +54,7 @@
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<AdditionalOptions>/bigobj</AdditionalOptions>
<AdditionalOptions Condition="'$(CppWinRTLanguageStandard)'==''">/await %(AdditionalOptions)</AdditionalOptions>
<AdditionalOptions Condition="'$(Clang)'=='1'">-Wno-unused-command-line-argument -fno-delayed-template-parsing -Xclang -fcoroutines-ts -mcx16</AdditionalOptions>
<AdditionalOptions Condition="'$(Clang)'=='1'">-Wno-unused-command-line-argument -fno-delayed-template-parsing -mcx16</AdditionalOptions>
</ClCompile>
<Link>
<AdditionalDependencies>onecore.lib</AdditionalDependencies>
Expand Down
30 changes: 12 additions & 18 deletions natvis/cppwinrtvisualizer.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,9 @@
<WarningLevel>Level4</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>false</SDLCheck>
<PreprocessorDefinitions>WIN32;_DEBUG;VISUALIZER_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>VSDEBUGENG_USE_CPP11_SCOPED_ENUMS;WIN32;_DEBUG;VISUALIZER_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>$(IntDir);..\cppwinrt;..\strings;$(DIASDKInc);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<LanguageStandard>stdcpp17</LanguageStandard>
<AdditionalOptions>/await</AdditionalOptions>
<LanguageStandard>stdcpp20</LanguageStandard>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
</ClCompile>
<ResourceCompile>
Expand All @@ -131,11 +130,10 @@
<WarningLevel>Level4</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>false</SDLCheck>
<PreprocessorDefinitions>_DEBUG;VISUALIZER_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>VSDEBUGENG_USE_CPP11_SCOPED_ENUMS;_DEBUG;VISUALIZER_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>$(IntDir);..\cppwinrt;..\strings;$(DIASDKInc);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<LanguageStandard>stdcpp17</LanguageStandard>
<LanguageStandard>stdcpp20</LanguageStandard>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<AdditionalOptions>/await</AdditionalOptions>
</ClCompile>
<ResourceCompile>
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
Expand All @@ -156,11 +154,10 @@
<WarningLevel>Level4</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>false</SDLCheck>
<PreprocessorDefinitions>_DEBUG;VISUALIZER_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>VSDEBUGENG_USE_CPP11_SCOPED_ENUMS;_DEBUG;VISUALIZER_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>$(IntDir);..\cppwinrt;..\strings;$(DIASDKInc);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<LanguageStandard>stdcpp17</LanguageStandard>
<LanguageStandard>stdcpp20</LanguageStandard>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<AdditionalOptions>/await</AdditionalOptions>
</ClCompile>
<ResourceCompile>
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
Expand All @@ -183,11 +180,10 @@
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>false</SDLCheck>
<PreprocessorDefinitions>WIN32;NDEBUG;VISUALIZER_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>VSDEBUGENG_USE_CPP11_SCOPED_ENUMS;WIN32;NDEBUG;VISUALIZER_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>$(IntDir);..\cppwinrt;..\strings;$(DIASDKInc);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<LanguageStandard>stdcpp17</LanguageStandard>
<LanguageStandard>stdcpp20</LanguageStandard>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<AdditionalOptions>/await</AdditionalOptions>
</ClCompile>
<ResourceCompile>
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
Expand All @@ -213,11 +209,10 @@
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>false</SDLCheck>
<PreprocessorDefinitions>NDEBUG;VISUALIZER_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>VSDEBUGENG_USE_CPP11_SCOPED_ENUMS;NDEBUG;VISUALIZER_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>$(IntDir);..\cppwinrt;..\strings;$(DIASDKInc);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<LanguageStandard>stdcpp17</LanguageStandard>
<LanguageStandard>stdcpp20</LanguageStandard>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<AdditionalOptions>/await</AdditionalOptions>
</ClCompile>
<ResourceCompile>
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
Expand All @@ -243,11 +238,10 @@
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>false</SDLCheck>
<PreprocessorDefinitions>NDEBUG;VISUALIZER_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>VSDEBUGENG_USE_CPP11_SCOPED_ENUMS;NDEBUG;VISUALIZER_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>$(IntDir);..\cppwinrt;..\strings;$(DIASDKInc);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<LanguageStandard>stdcpp17</LanguageStandard>
<LanguageStandard>stdcpp20</LanguageStandard>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<AdditionalOptions>/await</AdditionalOptions>
</ClCompile>
<ResourceCompile>
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
Expand Down
4 changes: 0 additions & 4 deletions strings/base_identity.h
Original file line number Diff line number Diff line change
Expand Up @@ -458,12 +458,8 @@ namespace winrt::impl
};

template <typename T>
#ifdef __clang__
inline static const auto name_v
#else
#pragma warning(suppress: 4307)
inline constexpr auto name_v
#endif
{
combine
(
Expand Down
17 changes: 11 additions & 6 deletions strings/base_meta.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,17 +117,22 @@ namespace winrt::impl
static constexpr auto data{ category_signature<category_t<T>, T>::data };
};

template <typename T>
#if defined(__clang__)
template <typename T>
struct classic_com_guid
{
#if __has_declspec_attribute(uuid) && defined(WINRT_IMPL_IUNKNOWN_DEFINED)
inline const guid guid_v{ __uuidof(T) };
static constexpr guid value{ __uuidof(T) };
#else
inline constexpr guid guid_v{};
static_assert(std::is_void_v<T> /* dependent_false */, "To use classic COM interfaces, you must compile with -fms-extensions and include <unknwn.h> before including C++/WinRT headers.");
#endif
#elif defined(_MSC_VER) && defined(WINRT_IMPL_IUNKNOWN_DEFINED)
inline constexpr guid guid_v{ __uuidof(T) };
};

template <typename T>
inline constexpr guid guid_v = classic_com_guid<T>::value;
#else
inline constexpr guid guid_v{};
template <typename T>
inline constexpr guid guid_v{ __uuidof(T) };
#endif

template <typename T>
Expand Down
4 changes: 0 additions & 4 deletions test/test/generic_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,5 @@ TEST_CASE("generic_types")
REQUIRE_EQUAL_NAME(L"Windows.Foundation.Uri", Uri);
REQUIRE_EQUAL_NAME(L"Windows.Foundation.PropertyType", PropertyType);
REQUIRE_EQUAL_NAME(L"Windows.Foundation.Point", Point);

// Clang 9 doesn't think this is a constant expression.
#ifndef __clang__
REQUIRE_EQUAL_NAME(L"Windows.Foundation.IStringable", IStringable);
#endif
}
4 changes: 0 additions & 4 deletions test/test_win7/generic_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,5 @@ TEST_CASE("generic_types")
REQUIRE_EQUAL_NAME(L"Windows.Foundation.Uri", Uri);
REQUIRE_EQUAL_NAME(L"Windows.Foundation.PropertyType", PropertyType);
REQUIRE_EQUAL_NAME(L"Windows.Foundation.Point", Point);

// Clang 9 doesn't think this is a constant expression.
#ifndef __clang__
REQUIRE_EQUAL_NAME(L"Windows.Foundation.IStringable", IStringable);
#endif
}

0 comments on commit e7b6903

Please sign in to comment.