From 7b1431eea88720a831308c15b2bdff0f94820cf1 Mon Sep 17 00:00:00 2001 From: Charles Milette Date: Sun, 25 Sep 2022 22:41:49 -0400 Subject: [PATCH 1/5] Make guid constexpr on clang, improve error reporting --- Directory.Build.Props | 3 +-- strings/base_identity.h | 4 ---- strings/base_meta.h | 16 +++++++++++----- test/test/generic_types.cpp | 4 ---- test/test_win7/generic_types.cpp | 4 ---- 5 files changed, 12 insertions(+), 19 deletions(-) diff --git a/Directory.Build.Props b/Directory.Build.Props index 858b09177..301d36e48 100644 --- a/Directory.Build.Props +++ b/Directory.Build.Props @@ -25,8 +25,7 @@ --> - clang-cl.exe - C:\Program Files\LLVM\bin + ClangCL diff --git a/strings/base_identity.h b/strings/base_identity.h index 5bf7bbaa8..52a77dfc4 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 4bfa82d18..0eca73f49 100644 --- a/strings/base_meta.h +++ b/strings/base_meta.h @@ -118,17 +118,23 @@ namespace winrt::impl }; template + struct classic_com_guid + { #if defined(__clang__) #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 #include before including C++/WinRT headers."); #endif -#elif defined(_MSC_VER) && defined(WINRT_IMPL_IUNKNOWN_DEFINED) - inline constexpr guid guid_v{ __uuidof(T) }; +#elif defined(_MSC_VER) + static constexpr guid value{ __uuidof(T) }; #else - inline constexpr guid guid_v{}; + static_assert(std::is_void_v /* dependent_false */, "Classic COM interfaces are not supported on this compiler"); #endif + }; + + template + inline constexpr guid guid_v = classic_com_guid::value; template constexpr auto to_underlying_type(T const value) noexcept diff --git a/test/test/generic_types.cpp b/test/test/generic_types.cpp index 98ffd12eb..081155cd2 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 98ffd12eb..081155cd2 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 } From c049e6f3f27501651ebe2a6f483a8c163ce4a38d Mon Sep 17 00:00:00 2001 From: Charles Milette Date: Sun, 25 Sep 2022 22:45:38 -0400 Subject: [PATCH 2/5] Remove a trailing whitespace that sneaked in --- strings/base_meta.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/strings/base_meta.h b/strings/base_meta.h index 0eca73f49..030e53b78 100644 --- a/strings/base_meta.h +++ b/strings/base_meta.h @@ -127,7 +127,7 @@ namespace winrt::impl static_assert(std::is_void_v /* dependent_false */, "To use classic COM interfaces, you must #include before including C++/WinRT headers."); #endif #elif defined(_MSC_VER) - static constexpr guid value{ __uuidof(T) }; + static constexpr guid value{ __uuidof(T) }; #else static_assert(std::is_void_v /* dependent_false */, "Classic COM interfaces are not supported on this compiler"); #endif From 2f340a53910f6df981023ace1b0eb2fa167f1a6a Mon Sep 17 00:00:00 2001 From: Charles Milette Date: Tue, 27 Sep 2022 01:15:44 -0400 Subject: [PATCH 3/5] Update strings/base_meta.h Co-authored-by: Raymond Chen --- strings/base_meta.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/strings/base_meta.h b/strings/base_meta.h index 030e53b78..5a0cde273 100644 --- a/strings/base_meta.h +++ b/strings/base_meta.h @@ -124,7 +124,7 @@ namespace winrt::impl #if __has_declspec_attribute(uuid) && defined(WINRT_IMPL_IUNKNOWN_DEFINED) static constexpr guid value{ __uuidof(T) }; #else - static_assert(std::is_void_v /* dependent_false */, "To use classic COM interfaces, you must #include before including C++/WinRT headers."); + 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) static constexpr guid value{ __uuidof(T) }; From e78a799f947ecb151707e9d729e6e106d4d2903f Mon Sep 17 00:00:00 2001 From: Charles Milette Date: Tue, 27 Sep 2022 01:48:51 -0400 Subject: [PATCH 4/5] Allow visualizer to build under Clang --- Directory.Build.Props | 6 +++++- natvis/cppwinrtvisualizer.vcxproj | 30 ++++++++++++------------------ 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/Directory.Build.Props b/Directory.Build.Props index 301d36e48..abbedf15b 100644 --- a/Directory.Build.Props +++ b/Directory.Build.Props @@ -26,6 +26,10 @@ ClangCL + + 20 + + false @@ -50,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 d7c3a4ae1..e504e197e 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) From 1a2440736388aadb3fd30628c9f345fb7b5b4cf7 Mon Sep 17 00:00:00 2001 From: Charles Milette Date: Wed, 28 Sep 2022 00:07:59 -0400 Subject: [PATCH 5/5] Fix compile-time regression on MSVC --- strings/base_meta.h | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/strings/base_meta.h b/strings/base_meta.h index 5a0cde273..f19e0513a 100644 --- a/strings/base_meta.h +++ b/strings/base_meta.h @@ -117,24 +117,23 @@ namespace winrt::impl static constexpr auto data{ category_signature, T>::data }; }; +#if defined(__clang__) template struct classic_com_guid { -#if defined(__clang__) #if __has_declspec_attribute(uuid) && defined(WINRT_IMPL_IUNKNOWN_DEFINED) static constexpr guid value{ __uuidof(T) }; #else 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) - static constexpr guid value{ __uuidof(T) }; -#else - static_assert(std::is_void_v /* dependent_false */, "Classic COM interfaces are not supported on this compiler"); #endif }; template inline constexpr guid guid_v = classic_com_guid::value; +#else + template + inline constexpr guid guid_v{ __uuidof(T) }; +#endif template constexpr auto to_underlying_type(T const value) noexcept