| 1 |
// P0466R5 |
| 2 |
// { dg-do run { target c++20 } } |
| 3 |
// { dg-options "" } |
| 4 |
|
| 5 |
namespace std |
| 6 |
{ |
| 7 |
template <class S1, class S2, class M1, class M2> |
| 8 |
constexpr bool |
| 9 |
is_corresponding_member (M1 S1::*m1, M2 S2::*m2) noexcept |
| 10 |
{ |
| 11 |
return __builtin_is_corresponding_member (m1, m2); |
| 12 |
} |
| 13 |
} |
| 14 |
|
| 15 |
struct A { int a; struct { int b; short c; long d; }; int : 0; int e; }; |
| 16 |
struct B { const signed int a; struct { int b; signed short c; signed long d; }; volatile int e; }; |
| 17 |
struct C { int a; union { struct { short b; long c; }; long d; short e; }; signed int f; }; |
| 18 |
struct D { int a; union { long b; short c; struct { short d; signed long e; }; }; int f; }; |
| 19 |
|
| 20 |
static_assert (std::is_corresponding_member (&A::a, &B::a)); |
| 21 |
static_assert (std::is_corresponding_member (&A::b, &B::b)); |
| 22 |
static_assert (std::is_corresponding_member (&A::c, &B::c)); |
| 23 |
static_assert (std::is_corresponding_member (&A::d, &B::d)); |
| 24 |
static_assert (!std::is_corresponding_member (&A::e, &B::e)); |
| 25 |
static_assert (!std::is_corresponding_member (&A::a, &B::b)); |
| 26 |
static_assert (!std::is_corresponding_member (&A::b, &B::a)); |
| 27 |
static_assert (std::is_corresponding_member (&C::a, &D::a)); |
| 28 |
static_assert (std::is_corresponding_member (&C::f, &D::f)); |
| 29 |
static_assert (!std::is_corresponding_member (&C::a, &D::f)); |
| 30 |
static_assert (!std::is_corresponding_member (&C::f, &D::a)); |
| 31 |
|
| 32 |
int |
| 33 |
main () |
| 34 |
{ |
| 35 |
auto t1 = &A::a; |
| 36 |
auto t2 = &B::a; |
| 37 |
auto t3 = &A::b; |
| 38 |
auto t4 = &B::b; |
| 39 |
auto t5 = &A::c; |
| 40 |
auto t6 = &B::c; |
| 41 |
auto t7 = &A::d; |
| 42 |
auto t8 = &B::d; |
| 43 |
auto t9 = &A::e; |
| 44 |
auto t10 = &B::e; |
| 45 |
if (!std::is_corresponding_member (t1, t2)) |
| 46 |
__builtin_abort (); |
| 47 |
if (!std::is_corresponding_member (t3, t4)) |
| 48 |
__builtin_abort (); |
| 49 |
if (!std::is_corresponding_member (t5, t6)) |
| 50 |
__builtin_abort (); |
| 51 |
if (!std::is_corresponding_member (t7, t8)) |
| 52 |
__builtin_abort (); |
| 53 |
if (std::is_corresponding_member (t9, t10)) |
| 54 |
__builtin_abort (); |
| 55 |
if (std::is_corresponding_member (t1, t4)) |
| 56 |
__builtin_abort (); |
| 57 |
if (std::is_corresponding_member (t3, t2)) |
| 58 |
__builtin_abort (); |
| 59 |
auto t11 = &C::a; |
| 60 |
auto t12 = &D::a; |
| 61 |
auto t13 = &C::f; |
| 62 |
auto t14 = &D::f; |
| 63 |
if (!std::is_corresponding_member (t11, t12)) |
| 64 |
__builtin_abort (); |
| 65 |
if (!std::is_corresponding_member (t13, t14)) |
| 66 |
__builtin_abort (); |
| 67 |
if (std::is_corresponding_member (t11, t14)) |
| 68 |
__builtin_abort (); |
| 69 |
if (std::is_corresponding_member (t13, t12)) |
| 70 |
__builtin_abort (); |
| 71 |
} |