From e7b690382e0e08af0ce5ddcfde37d8fdab0ddb24 Mon Sep 17 00:00:00 2001 From: Charles Milette Date: Thu, 29 Sep 2022 09:44:40 -0400 Subject: [PATCH] Make `guid` `constexpr` on Clang and improve error reporting (#1191) --- Directory.Build.Props | 9 ++++++--- natvis/cppwinrtvisualizer.vcxproj | 30 ++++++++++++------------------ strings/base_identity.h | 4 ---- strings/base_meta.h | 17 +++++++++++------ test/test/generic_types.cpp | 4 ---- test/test_win7/generic_types.cpp | 4 ---- 6 files changed, 29 insertions(+), 39 deletions(-) diff --git a/Directory.Build.Props b/Directory.Build.Props index 858b0917..abbedf15 100644 --- a/Directory.Build.Props +++ b/Directory.Build.Props @@ -25,8 +25,11 @@ --> - clang-cl.exe - C:\Program Files\LLVM\bin + ClangCL + + 20 + + false @@ -51,7 +54,7 @@ true /bigobj /await %(AdditionalOptions) - -Wno-unused-command-line-argument -fno-delayed-template-parsing -Xclang -fcoroutines-ts -mcx16 + -Wno-unused-command-line-argument -fno-delayed-template-parsing -mcx16 onecore.lib diff --git a/natvis/cppwinrtvisualizer.vcxproj b/natvis/cppwinrtvisualizer.vcxproj index d7c3a4ae..e504e197 100644 --- a/natvis/cppwinrtvisualizer.vcxproj +++ b/natvis/cppwinrtvisualizer.vcxproj @@ -105,10 +105,9 @@ Level4 Disabled false - WIN32;_DEBUG;VISUALIZER_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + VSDEBUGENG_USE_CPP11_SCOPED_ENUMS;WIN32;_DEBUG;VISUALIZER_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) $(IntDir);..\cppwinrt;..\strings;$(DIASDKInc);%(AdditionalIncludeDirectories) - stdcpp17 - /await + stdcpp20 pch.h @@ -131,11 +130,10 @@ Level4 Disabled false - _DEBUG;VISUALIZER_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + VSDEBUGENG_USE_CPP11_SCOPED_ENUMS;_DEBUG;VISUALIZER_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) $(IntDir);..\cppwinrt;..\strings;$(DIASDKInc);%(AdditionalIncludeDirectories) - stdcpp17 + stdcpp20 pch.h - /await _DEBUG;%(PreprocessorDefinitions) @@ -156,11 +154,10 @@ Level4 Disabled false - _DEBUG;VISUALIZER_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + VSDEBUGENG_USE_CPP11_SCOPED_ENUMS;_DEBUG;VISUALIZER_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) $(IntDir);..\cppwinrt;..\strings;$(DIASDKInc);%(AdditionalIncludeDirectories) - stdcpp17 + stdcpp20 pch.h - /await _DEBUG;%(PreprocessorDefinitions) @@ -183,11 +180,10 @@ true true false - WIN32;NDEBUG;VISUALIZER_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + VSDEBUGENG_USE_CPP11_SCOPED_ENUMS;WIN32;NDEBUG;VISUALIZER_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) $(IntDir);..\cppwinrt;..\strings;$(DIASDKInc);%(AdditionalIncludeDirectories) - stdcpp17 + stdcpp20 pch.h - /await _DEBUG;%(PreprocessorDefinitions) @@ -213,11 +209,10 @@ true true false - NDEBUG;VISUALIZER_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + VSDEBUGENG_USE_CPP11_SCOPED_ENUMS;NDEBUG;VISUALIZER_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) $(IntDir);..\cppwinrt;..\strings;$(DIASDKInc);%(AdditionalIncludeDirectories) - stdcpp17 + stdcpp20 pch.h - /await _DEBUG;%(PreprocessorDefinitions) @@ -243,11 +238,10 @@ true true false - NDEBUG;VISUALIZER_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + VSDEBUGENG_USE_CPP11_SCOPED_ENUMS;NDEBUG;VISUALIZER_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) $(IntDir);..\cppwinrt;..\strings;$(DIASDKInc);%(AdditionalIncludeDirectories) - stdcpp17 + stdcpp20 pch.h - /await _DEBUG;%(PreprocessorDefinitions) diff --git a/strings/base_identity.h b/strings/base_identity.h index 5bf7bbaa..52a77dfc 100644 --- a/strings/base_identity.h +++ b/strings/base_identity.h @@ -458,12 +458,8 @@ namespace winrt::impl }; template -#ifdef __clang__ - inline static const auto name_v -#else #pragma warning(suppress: 4307) inline constexpr auto name_v -#endif { combine ( diff --git a/strings/base_meta.h b/strings/base_meta.h index 4bfa82d1..f19e0513 100644 --- a/strings/base_meta.h +++ b/strings/base_meta.h @@ -117,17 +117,22 @@ namespace winrt::impl static constexpr auto data{ category_signature, T>::data }; }; - template #if defined(__clang__) + template + 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 /* dependent_false */, "To use classic COM interfaces, you must compile with -fms-extensions and include before including C++/WinRT headers."); #endif -#elif defined(_MSC_VER) && defined(WINRT_IMPL_IUNKNOWN_DEFINED) - inline constexpr guid guid_v{ __uuidof(T) }; + }; + + template + inline constexpr guid guid_v = classic_com_guid::value; #else - inline constexpr guid guid_v{}; + template + inline constexpr guid guid_v{ __uuidof(T) }; #endif template diff --git a/test/test/generic_types.cpp b/test/test/generic_types.cpp index 98ffd12e..081155cd 100644 --- a/test/test/generic_types.cpp +++ b/test/test/generic_types.cpp @@ -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 } diff --git a/test/test_win7/generic_types.cpp b/test/test_win7/generic_types.cpp index 98ffd12e..081155cd 100644 --- a/test/test_win7/generic_types.cpp +++ b/test/test_win7/generic_types.cpp @@ -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 }