| 1 |
// PR c++/98193 |
| 2 |
// { dg-do compile { target c++20 } } |
| 3 |
|
| 4 |
template <typename To, typename From> |
| 5 |
constexpr To |
| 6 |
bit_cast (const From &from) |
| 7 |
{ |
| 8 |
return __builtin_bit_cast (To, from); |
| 9 |
} |
| 10 |
|
| 11 |
struct J |
| 12 |
{ |
| 13 |
long int a, b : 11, h; |
| 14 |
}; |
| 15 |
|
| 16 |
struct K |
| 17 |
{ |
| 18 |
long int a, b : 11, c; |
| 19 |
constexpr bool operator == (const K &x) const |
| 20 |
{ |
| 21 |
return a == x.a && b == x.b && c == x.c; |
| 22 |
} |
| 23 |
}; |
| 24 |
|
| 25 |
struct L |
| 26 |
{ |
| 27 |
long long int a, b : 11, h; |
| 28 |
}; |
| 29 |
struct M |
| 30 |
{ |
| 31 |
long long int a, b : 11, c; |
| 32 |
constexpr bool operator == (const M &x) const |
| 33 |
{ |
| 34 |
return a == x.a && b == x.b && c == x.c; |
| 35 |
} |
| 36 |
}; |
| 37 |
|
| 38 |
static_assert (bit_cast <K> (J{}) == K{}, ""); |
| 39 |
static_assert (bit_cast <M> (L{0x0feedbacdeadbeefLL}) == M{0x0feedbacdeadbeefLL}, ""); |