Skip to content

Commit 94787ce

Browse files
committed
Add a guid constructor overload taking Data4 by reference to array
The guid constructor takes Data4 as std::array<std::uint8_t, 8> const&. Because std::array wraps a C array, a braced call site elides the inner braces and MSVC reports C5246, "the initialization of a subobject should be wrapped in braces", at every such call site - including the guid literals C++/WinRT generates for each namespace header. Suppressing the warning around the constructor does not work, because the diagnostic is attributed to the caller rather than to the constructor. Add an overload taking std::uint8_t const (&)[8] rather than replacing the existing parameter. A braced initializer then binds to the C array directly, with no intervening subobject and no warning, while callers passing a std::array continue to compile unchanged. Measured on a /Wall build of a translation unit exercising collections, coroutines, delegates, implements, factories and classic COM: C5246 falls from 114 to 20, with no other diagnostic changes.
1 parent 856eaff commit 94787ce

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

‎strings/base_types.h‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,14 @@ WINRT_EXPORT namespace winrt
140140

141141
guid() noexcept = default;
142142

143+
constexpr guid(std::uint32_t const Data1, std::uint16_t const Data2, std::uint16_t const Data3, std::uint8_t const (&Data4)[8]) noexcept :
144+
Data1(Data1),
145+
Data2(Data2),
146+
Data3(Data3),
147+
Data4{ Data4[0], Data4[1], Data4[2], Data4[3], Data4[4], Data4[5], Data4[6], Data4[7] }
148+
{
149+
}
150+
143151
constexpr guid(std::uint32_t const Data1, std::uint16_t const Data2, std::uint16_t const Data3, std::array<std::uint8_t, 8> const& Data4) noexcept :
144152
Data1(Data1),
145153
Data2(Data2),

0 commit comments

Comments
 (0)