| 1 |
// P0466R5 |
| 2 |
// { dg-do compile { target c++20 } } |
| 3 |
// { dg-options "-pedantic" } |
| 4 |
|
| 5 |
namespace std |
| 6 |
{ |
| 7 |
template <typename T, T v> |
| 8 |
struct integral_constant |
| 9 |
{ |
| 10 |
static constexpr T value = v; |
| 11 |
}; |
| 12 |
|
| 13 |
template <typename, typename> |
| 14 |
struct is_layout_compatible; |
| 15 |
|
| 16 |
template<typename T, typename U> |
| 17 |
struct is_layout_compatible |
| 18 |
: public integral_constant <bool, __is_layout_compatible (T, U)> |
| 19 |
{ |
| 20 |
}; |
| 21 |
|
| 22 |
template <typename T, typename U> |
| 23 |
inline constexpr bool is_layout_compatible_v = __is_layout_compatible (T, U); |
| 24 |
} |
| 25 |
|
| 26 |
// Weird cases. |
| 27 |
struct S {}; |
| 28 |
struct T {}; |
| 29 |
struct I { int a; }; |
| 30 |
struct alignas(16) J { const int b; }; |
| 31 |
struct K { I c; int d; }; |
| 32 |
struct L { J e; int f; }; |
| 33 |
union M { I u; }; |
| 34 |
union N { J v; }; |
| 35 |
union O { int a; int b; }; |
| 36 |
union P { int a : 1; int b : 12; }; |
| 37 |
enum Q : int { Q1, Q2 }; |
| 38 |
enum alignas(16) R : int { R1, R2 }; // { dg-warning "'alignas' on enumerated type" } |
| 39 |
struct U { [[no_unique_address]] S a1; [[no_unique_address]] S a2; [[no_unique_address]] S a3; }; |
| 40 |
struct V { [[no_unique_address]] S b1; [[no_unique_address]] T b2; [[no_unique_address]] S b3; }; |
| 41 |
struct alignas(16) A : public I {}; |
| 42 |
struct alignas(16) B {}; |
| 43 |
struct C : public B, public I {}; |
| 44 |
union D { int a : 3; int b : 9; }; |
| 45 |
struct alignas(16) E { alignas(16) int a; alignas(16) int b; }; |
| 46 |
struct alignas(16) F { int c; alignas(16) int d; }; |
| 47 |
union alignas(16) G { int a; alignas(16) short b; }; |
| 48 |
union alignas(16) H { short c; int d; }; |
| 49 |
struct A1 { int a; }; |
| 50 |
struct B1 { signed int b; }; |
| 51 |
struct alignas (16) C1 : public A1 {}; |
| 52 |
struct alignas (16) D1 : public B1 {}; |
| 53 |
|
| 54 |
static_assert (!std::is_layout_compatible_v<I, J>); |
| 55 |
static_assert (!std::is_layout_compatible_v<K, L>); |
| 56 |
static_assert (!std::is_layout_compatible_v<M, N>); |
| 57 |
static_assert (!std::is_layout_compatible_v<O, P>); |
| 58 |
static_assert (!std::is_layout_compatible_v<P, D>); |
| 59 |
static_assert (std::is_layout_compatible_v<Q, R>); |
| 60 |
static_assert (!std::is_layout_compatible_v<U, V>); |
| 61 |
static_assert (!std::is_layout_compatible_v<A, I>); |
| 62 |
static_assert (!std::is_layout_compatible_v<C, I>); |
| 63 |
static_assert (!std::is_layout_compatible_v<E, F>); |
| 64 |
static_assert (std::is_layout_compatible_v<G, H>); |
| 65 |
static_assert (std::is_layout_compatible_v<C1, D1>); |