2 // { dg-do compile { target c++20 } }
6 enum class byte : unsigned char {};
7 template <typename To, typename From>
9 bit_cast (const From &from)
11 return __builtin_bit_cast (To, from);
15 struct S { unsigned short s[2]; };
16 constexpr std::byte from1[sizeof (S)]{};
17 constexpr auto to1 = std::bit_cast<S>(from1);
18 constexpr unsigned char from2[sizeof (S)]{};
19 constexpr auto to2 = std::bit_cast<S>(from2);
22 cmp (const S &s1, const S &s2)
24 for (int i = 0; i < sizeof (s1.s) / sizeof (s1.s[0]); i++)
25 if (s1.s[i] != s2.s[i])
30 static_assert (cmp (to1, S{}));
31 static_assert (cmp (to2, S{}));