Debian Codegraph @

gcc/testsuite/g++.dg/cpp2a/is-corresponding-member5.C

raw
1 // P0466R5
2 // { dg-do run { target c++20 } }
3
4 namespace std
5 {
6 template <class S1, class S2, class M1, class M2>
7 constexpr bool
8 is_corresponding_member (M1 S1::*m1, M2 S2::*m2) noexcept
9 {
10 return __builtin_is_corresponding_member (m1, m2);
11 }
12 }
13
14 struct S {};
15 struct T {};
16 struct I { int a; };
17 struct alignas(16) J { const int b; };
18 struct K { char b; char s[15]; I c; short d; };
19 struct L { char d; char t[15]; J e; short f; };
20 struct U { int a0; [[no_unique_address]] S a1; [[no_unique_address]] S a2; [[no_unique_address]] S a3; short a4; };
21 struct V { int b0; [[no_unique_address]] S b1; [[no_unique_address]] T b2; [[no_unique_address]] S b3; short b4; };
22 struct U1 { int a0; [[no_unique_address]] S a1; [[no_unique_address]] S a2; [[no_unique_address]] S a3; short a4; };
23 struct V1 { int b0; [[no_unique_address]] S b1; [[no_unique_address]] T b2; [[no_unique_address]] S b3; short b4; };
24 struct A { int a; union { short b; long c; }; int d; signed char e; int f; };
25 struct B { const int a; union { signed long b; short c; }; volatile int d; unsigned char e; int f; };
26 struct A1 { int a; union { short b; long c; }; int d; short e; int f; };
27 struct B1 { const int a; union { signed long b; short c; }; volatile int d; unsigned short e; int f; };
28
29 static_assert (std::is_corresponding_member (&I::a, &J::b));
30 static_assert (std::is_corresponding_member (&K::b, &L::d));
31 static_assert (!std::is_corresponding_member (&K::c, &L::e));
32 static_assert (std::is_corresponding_member (&U::a0, &V::b0));
33 static_assert (!std::is_corresponding_member (&U::a4, &V::b4));
34 static_assert (std::is_corresponding_member (&A::a, &B::a));
35 static_assert (std::is_corresponding_member (&A::d, &B::d));
36 static_assert (!std::is_corresponding_member (&A::e, &B::e));
37 static_assert (!std::is_corresponding_member (&A::f, &B::f));
38 static_assert (!std::is_corresponding_member (&A::a, &B::f));
39 static_assert (!std::is_corresponding_member (&A::d, &B::a));
40 static_assert (!std::is_corresponding_member (&A::a, &B::d));
41 static_assert (!std::is_corresponding_member (&A::f, &B::a));
42 static_assert (!std::is_corresponding_member (&A1::e, &B1::e));
43
44 int
45 main ()
46 {
47 auto t1 = &I::a;
48 auto t2 = &J::b;
49 if (!std::is_corresponding_member (t1, t2))
50 __builtin_abort ();
51 auto t3 = &K::b;
52 auto t4 = &L::d;
53 if (!std::is_corresponding_member (t3, t4))
54 __builtin_abort ();
55 auto t5 = &K::c;
56 auto t6 = &L::e;
57 if (std::is_corresponding_member (t5, t6))
58 __builtin_abort ();
59 auto t7 = &U::a0;
60 auto t8 = &V::b0;
61 if (!std::is_corresponding_member (t7, t8))
62 __builtin_abort ();
63 auto t9 = &U::a4;
64 auto t10 = &V::b4;
65 if (std::is_corresponding_member (t9, t10))
66 __builtin_abort ();
67 auto t11 = &A::a;
68 auto t12 = &B::a;
69 auto t13 = &A::d;
70 auto t14 = &B::d;
71 auto t15 = &A::e;
72 auto t16 = &B::e;
73 auto t17 = &A::f;
74 auto t18 = &B::f;
75 if (!std::is_corresponding_member (t11, t12))
76 __builtin_abort ();
77 if (!std::is_corresponding_member (t13, t14))
78 __builtin_abort ();
79 if (std::is_corresponding_member (t15, t16))
80 __builtin_abort ();
81 if (std::is_corresponding_member (t17, t18))
82 __builtin_abort ();
83 if (std::is_corresponding_member (t11, t18))
84 __builtin_abort ();
85 if (std::is_corresponding_member (t13, t12))
86 __builtin_abort ();
87 if (std::is_corresponding_member (t11, t14))
88 __builtin_abort ();
89 if (std::is_corresponding_member (t17, t12))
90 __builtin_abort ();
91 auto t19 = &A1::e;
92 auto t20 = &B1::e;
93 if (std::is_corresponding_member (t19, t20))
94 __builtin_abort ();
95 }