| 1 |
// PR c++/114706 |
| 2 |
// { dg-do compile { target c++20 } } |
| 3 |
|
| 4 |
namespace std { |
| 5 |
template<typename T, typename F> |
| 6 |
constexpr T |
| 7 |
bit_cast (const F& f) noexcept |
| 8 |
{ |
| 9 |
return __builtin_bit_cast (T, f); |
| 10 |
} |
| 11 |
} |
| 12 |
// { dg-error "'__builtin_bit_cast' is not a constant expression because 'const A' contains a union type" "" { target *-*-* } .-3 } |
| 13 |
// { dg-error "'__builtin_bit_cast' is not a constant expression because 'A' contains a union type" "" { target *-*-* } .-4 } |
| 14 |
// { dg-error "'__builtin_bit_cast' is not a constant expression because 'const C' contains a union type" "" { target *-*-* } .-5 } |
| 15 |
// { dg-error "'__builtin_bit_cast' is not a constant expression because 'C' contains a union type" "" { target *-*-* } .-6 } |
| 16 |
// { dg-error "'__builtin_bit_cast' is not a constant expression because 'const E' contains a pointer type" "" { target *-*-* } .-7 } |
| 17 |
// { dg-error "'__builtin_bit_cast' is not a constant expression because 'E' contains a pointer type" "" { target *-*-* } .-8 } |
| 18 |
|
| 19 |
union U { int a; int b; }; |
| 20 |
struct A { U c[2]; }; |
| 21 |
struct B { int d[2]; }; |
| 22 |
struct C { U e[2][2]; }; |
| 23 |
struct D { int f[2][2]; }; |
| 24 |
struct E { int *g[3]; }; |
| 25 |
struct F { char h[sizeof (int *) * 3]; }; |
| 26 |
constexpr B i = std::bit_cast<B> (A{}); // { dg-message "in 'constexpr' expansion of 'std::bit_cast<" } |
| 27 |
constexpr A j = std::bit_cast<A> (B{}); // { dg-message "in 'constexpr' expansion of 'std::bit_cast<" } |
| 28 |
constexpr D k = std::bit_cast<D> (C{}); // { dg-message "in 'constexpr' expansion of 'std::bit_cast<" } |
| 29 |
constexpr C l = std::bit_cast<C> (D{}); // { dg-message "in 'constexpr' expansion of 'std::bit_cast<" } |
| 30 |
constexpr F m = std::bit_cast<F> (E{}); // { dg-message "in 'constexpr' expansion of 'std::bit_cast<" } |
| 31 |
constexpr E n = std::bit_cast<E> (F{}); // { dg-message "in 'constexpr' expansion of 'std::bit_cast<" } |