Skip to content

Commit 61b054a

Browse files
authored
Fix classic COM errors on non-supported compilers (#1194)
1 parent e7b6903 commit 61b054a

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

strings/base_meta.h

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -117,22 +117,33 @@ namespace winrt::impl
117117
static constexpr auto data{ category_signature<category_t<T>, T>::data };
118118
};
119119

120-
#if defined(__clang__)
121120
template <typename T>
122-
struct classic_com_guid
121+
struct classic_com_guid_error
123122
{
124-
#if __has_declspec_attribute(uuid) && defined(WINRT_IMPL_IUNKNOWN_DEFINED)
125-
static constexpr guid value{ __uuidof(T) };
126-
#else
127-
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.");
123+
#ifdef __clang__
124+
#if !__has_declspec_attribute(uuid)
125+
static_assert(std::is_void_v<T> /* dependent_false */, "To use classic COM interfaces, you must compile with -fms-extensions.");
126+
#endif
127+
128+
#ifndef WINRT_IMPL_IUNKNOWN_DEFINED
129+
static_assert(std::is_void_v<T> /* dependent_false */, "To use classic COM interfaces, you must include <unknwn.h> before including C++/WinRT headers.");
130+
#endif
131+
#else // MSVC won't hit this struct, so we can safely assume everything that isn't Clang isn't supported
132+
static_assert(std::is_void_v<T> /* dependent_false */, "Classic COM interfaces are not supported with this compiler.");
128133
#endif
129134
};
130135

131136
template <typename T>
132-
inline constexpr guid guid_v = classic_com_guid<T>::value;
137+
#ifdef __clang__
138+
#if __has_declspec_attribute(uuid) && defined(WINRT_IMPL_IUNKNOWN_DEFINED)
139+
inline constexpr guid guid_v{ __uuidof(T) };
133140
#else
134-
template <typename T>
141+
inline constexpr guid guid_v = classic_com_guid_error<T>::value;
142+
#endif
143+
#elif defined(_MSC_VER)
135144
inline constexpr guid guid_v{ __uuidof(T) };
145+
#else
146+
inline constexpr guid guid_v = classic_com_guid_error<T>::value;
136147
#endif
137148

138149
template <typename T>

0 commit comments

Comments
 (0)