| 1 |
// PR libstd++/93121 |
| 2 |
// { dg-do compile { target c++20 } } |
| 3 |
|
| 4 |
namespace std |
| 5 |
{ |
| 6 |
enum class byte : unsigned char {}; |
| 7 |
template <typename To, typename From> |
| 8 |
constexpr To |
| 9 |
bit_cast (const From &from) |
| 10 |
{ |
| 11 |
return __builtin_bit_cast (To, from); |
| 12 |
} |
| 13 |
} |
| 14 |
|
| 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); |
| 20 |
|
| 21 |
constexpr bool |
| 22 |
cmp (const S &s1, const S &s2) |
| 23 |
{ |
| 24 |
for (int i = 0; i < sizeof (s1.s) / sizeof (s1.s[0]); i++) |
| 25 |
if (s1.s[i] != s2.s[i]) |
| 26 |
return false; |
| 27 |
return true; |
| 28 |
} |
| 29 |
|
| 30 |
static_assert (cmp (to1, S{})); |
| 31 |
static_assert (cmp (to2, S{})); |