| 1 | // { dg-do compile { target c++20 } } |
| 2 | |
| 3 | // PR libstdc++/105027 - Missing constraints on std::bit_cast |
| 4 | |
| 5 | #include <bit> |
| 6 | |
| 7 | template<class T, class U> |
| 8 | concept BitCastable = requires(const U& u) { std::bit_cast<T>(u); }; |
| 9 | |
| 10 | static_assert(BitCastable<int, unsigned>); // OK |
| 11 | |
| 12 | static_assert(!BitCastable<int, char>); // #1: different size |
| 13 | |
| 14 | struct A { A(A const&); int i; }; |
| 15 | static_assert(!BitCastable<int, A>); // #2: not trivially copyable |
| 16 | |
| 17 | static_assert(!BitCastable<long, int()>); // #3: sizeof(int()) is ill-formed |