Debian Codegraph @

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

raw
1 // P0466R5
2 // { dg-do compile { 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 A { int a; };
15 struct B { const int b; };
16 struct C { int a; unsigned int b; int f; A c; int : 0; int d; double e; };
17 struct D { const int x; unsigned int y; int g; B z; int u; double w; };
18 struct E { int a; [[no_unique_address]] int b; };
19 struct F { int c; const int d; };
20 struct G { double a; int b; double c; };
21 struct H { const volatile double d; int e : 16; double f; };
22 struct I { const double g; int h : 15; const double i; };
23 struct J : public A {};
24 struct K {};
25 struct L : public K, public B {};
26 union U { int a; };
27 struct V { void foo () {}; };
28 struct W { int a; private: int b; public: int c; };
29 struct Z : public A, public B {};
30
31 static_assert (std::is_corresponding_member (&A::a, &A::a));
32 static_assert (std::is_corresponding_member (&A::a, &B::b));
33 static_assert (std::is_corresponding_member (&C::a, &D::x));
34 static_assert (std::is_corresponding_member (&C::b, &D::y));
35 static_assert (std::is_corresponding_member (&C::f, &D::g));
36 static_assert (std::is_corresponding_member (&C::c, &D::z));
37 static_assert (!std::is_corresponding_member (&C::d, &D::u));
38 static_assert (!std::is_corresponding_member (&C::e, &D::w));
39 static_assert (!std::is_corresponding_member (&C::f, &D::x));
40 static_assert (!std::is_corresponding_member (&C::a, &D::g));
41 static_assert (std::is_corresponding_member (&E::a, &F::c));
42 static_assert (!std::is_corresponding_member (&E::b, &F::d));
43 static_assert (std::is_corresponding_member (&G::a, &H::d));
44 static_assert (!std::is_corresponding_member (&G::c, &H::f));
45 static_assert (std::is_corresponding_member (&H::d, &I::g));
46 static_assert (!std::is_corresponding_member (&H::f, &I::i));
47 static_assert (std::is_corresponding_member (&J::a, &B::b));
48 static_assert (std::is_corresponding_member<J, B, int, const int> (&J::a, &B::b));
49 static_assert (std::is_corresponding_member (&J::a, &L::b));
50 static_assert (std::is_corresponding_member<J, L, int, const int> (&J::a, &L::b));
51 static_assert (std::is_corresponding_member (&L::b, &B::b));
52 static_assert (std::is_corresponding_member<L, B, const int, const int> (&L::b, &B::b));
53 static_assert (!std::is_corresponding_member (&U::a, &U::a));
54 static_assert (!std::is_corresponding_member (&A::a, (int A::*) nullptr));
55 static_assert (!std::is_corresponding_member ((int A::*) nullptr, &A::a));
56 static_assert (!std::is_corresponding_member ((int A::*) nullptr, (int A::*) nullptr));
57 static_assert (!std::is_corresponding_member (&V::foo, &V::foo));
58 static_assert (!std::is_corresponding_member (&W::a, &W::a));
59 static_assert (!std::is_corresponding_member (&W::c, &W::c));
60 static_assert (std::is_corresponding_member (&Z::a, &Z::b));
61 static_assert (!std::is_corresponding_member<Z, Z, int, const int> (&Z::a, &Z::b));