131
|
1 // P1064R0
|
|
2 // { dg-do compile }
|
|
3 // { dg-options "-std=c++2a" }
|
|
4
|
|
5 struct X1
|
|
6 {
|
|
7 virtual int f() const = 0;
|
|
8 virtual int f(int) const = 0;
|
|
9 virtual int f(int, int) const = 0;
|
|
10 };
|
|
11
|
|
12 struct X2: public X1
|
|
13 {
|
|
14 constexpr virtual int f() const { return 2; }
|
|
15 constexpr virtual int f(int) const { return 12; }
|
|
16 constexpr virtual int f(int, int) const { return 22; }
|
|
17 };
|
|
18
|
|
19 struct X3: public X2
|
|
20 {
|
|
21 virtual int f() const { return 3; }
|
|
22 virtual int f(int) const { return 13; }
|
|
23 virtual int f(int, int) const { return 23; }
|
|
24 };
|
|
25
|
|
26 struct X4: public X3
|
|
27 {
|
|
28 constexpr virtual int f() const { return 4; }
|
|
29 constexpr virtual int f(int) const { return 14; }
|
|
30 constexpr virtual int f(int, int) const { return 24; }
|
|
31 };
|
|
32
|
|
33 constexpr int (X1::*pf)() const = &X1::f;
|
|
34 constexpr int (X1::*pf1)(int) const = &X1::f;
|
|
35 constexpr int (X1::*pf2)(int, int) const = &X1::f;
|
|
36
|
|
37 constexpr X2 x2;
|
|
38 static_assert(x2.f() == 2);
|
|
39 static_assert((x2.*pf)() == 2);
|
|
40 static_assert(x2.f(1) == 12);
|
|
41 static_assert((x2.*pf1)(1) == 12);
|
|
42 static_assert(x2.f(1, 2) == 22);
|
|
43 static_assert((x2.*pf2)(1, 2) == 22);
|
|
44
|
|
45 constexpr X1 const& r2 = x2;
|
|
46 static_assert(r2.f() == 2);
|
|
47 static_assert((r2.*pf)() == 2);
|
|
48 static_assert(r2.f(1) == 12);
|
|
49 static_assert((r2.*pf1)(1) == 12);
|
|
50 static_assert(r2.f(1, 2) == 22);
|
|
51 static_assert((r2.*pf2)(1, 2) == 22);
|
|
52
|
|
53 constexpr X1 const* p2 = &x2;
|
|
54 static_assert(p2->f() == 2);
|
|
55 static_assert((p2->*pf)() == 2);
|
|
56 static_assert(p2->f(1) == 12);
|
|
57 static_assert((p2->*pf1)(1) == 12);
|
|
58 static_assert(p2->f(1, 2) == 22);
|
|
59 static_assert((p2->*pf2)(1, 2) == 22);
|
|
60
|
|
61 constexpr X4 x4;
|
|
62 static_assert(x4.f() == 4);
|
|
63 static_assert((x4.*pf)() == 4);
|
|
64 static_assert(x4.f(1) == 14);
|
|
65 static_assert((x4.*pf1)(1) == 14);
|
|
66 static_assert(x4.f(1, 2) == 24);
|
|
67 static_assert((x4.*pf2)(1, 2) == 24);
|
|
68
|
|
69 constexpr X1 const& r4 = x4;
|
|
70 static_assert(r4.f() == 4);
|
|
71 static_assert((r4.*pf)() == 4);
|
|
72 static_assert(r4.f(1) == 14);
|
|
73 static_assert((r4.*pf1)(1) == 14);
|
|
74 static_assert(r4.f(1, 2) == 24);
|
|
75 static_assert((r4.*pf2)(1, 2) == 24);
|
|
76
|
|
77 constexpr X1 const* p4 = &x4;
|
|
78 static_assert(p4->f() == 4);
|
|
79 static_assert((p4->*pf)() == 4);
|
|
80 static_assert(p4->f(1) == 14);
|
|
81 static_assert((p4->*pf1)(1) == 14);
|
|
82 static_assert(p4->f(1, 2) == 24);
|
|
83 static_assert((p4->*pf2)(1, 2) == 24);
|