Debian Codegraph @

gcc/testsuite/g++.dg/cpp23/explicit-obj-basic1.C

raw
1 // P0847R7
2 // { dg-do compile { target c++23 } }
3
4 // basic use cases and calling
5
6 // non-trailing return
7 // definitions
8 struct S0 {
9 void f0(this S0) {}
10 void f1(this S0&) {}
11 void f2(this S0&&) {}
12 void f3(this S0 const&) {}
13 void f4(this S0 const&&) {}
14 template<typename Self>
15 void d0(this Self&&) {}
16 void d1(this auto&&) {}
17 };
18 // declarations
19 struct S1 {
20 void f0(this S1);
21 void f1(this S1&);
22 void f2(this S1&&);
23 void f3(this S1 const&);
24 void f4(this S1 const&&);
25 template<typename Self>
26 void d0(this Self&&);
27 void d1(this auto&&);
28 };
29 // out of line definitions
30 void S1::f0(this S1) {}
31 void S1::f1(this S1&) {}
32 void S1::f2(this S1&&) {}
33 void S1::f3(this S1 const&) {}
34 void S1::f4(this S1 const&&) {}
35 template<typename Self>
36 void S1::d0(this Self&&) {}
37 void S1::d1(this auto&&) {}
38
39 // trailing return
40 // definitions
41 struct S2 {
42 auto f0(this S2) -> void {}
43 auto f1(this S2&) -> void {}
44 auto f2(this S2&&) -> void {}
45 auto f3(this S2 const&) -> void {}
46 auto f4(this S2 const&&) -> void {}
47 template<typename Self>
48 auto d0(this Self&&) -> void {}
49
50 auto d1(this auto&&) -> void {}
51 };
52 // declarations
53 struct S3 {
54 auto f0(this S3) -> void;
55 auto f1(this S3&) -> void;
56 auto f2(this S3&&) -> void;
57 auto f3(this S3 const&) -> void;
58 auto f4(this S3 const&&) -> void;
59 template<typename Self>
60 auto d0(this Self&&) -> void;
61 auto d1(this auto&&) -> void;
62 };
63 // out of line definitions
64 auto S3::f0(this S3) -> void {}
65 auto S3::f1(this S3&) -> void {}
66 auto S3::f2(this S3&&) -> void {}
67 auto S3::f3(this S3 const&) -> void {}
68 auto S3::f4(this S3 const&&) -> void {}
69 template<typename Self>
70 auto S3::d0(this Self&&) -> void {}
71 auto S3::d1(this auto&&) -> void {}
72
73 template<typename T>
74 void call_with_qualification()
75 {
76 T obj{};
77 // by value should take any qualification (f0)
78 T{}.f0();
79 obj.f0();
80 static_cast<T&&>(obj).f0();
81 static_cast<T const&>(obj).f0();
82 static_cast<T const&&>(obj).f0();
83 // specific qualification (f1 - f4)
84 T{}.f2();
85 T{}.f3();
86 T{}.f4();
87 obj.f1();
88 obj.f3();
89 static_cast<T&&>(obj).f2();
90 static_cast<T&&>(obj).f3();
91 static_cast<T&&>(obj).f4();
92 static_cast<T const&>(obj).f3();
93 static_cast<T const&&>(obj).f4();
94 // deduced should (obviously) take any qualification (d0, d1)
95 T{}.d0();
96 obj.d0();
97 static_cast<T&&>(obj).d0();
98 static_cast<T const&>(obj).d0();
99 static_cast<T const&&>(obj).d0();
100 T{}.d1();
101 obj.d1();
102 static_cast<T&&>(obj).d1();
103 static_cast<T const&>(obj).d1();
104 static_cast<T const&&>(obj).d1();
105 }
106
107 void perform_calls()
108 {
109 call_with_qualification<S0>();
110 call_with_qualification<S1>();
111 call_with_qualification<S2>();
112 call_with_qualification<S3>();
113 }
114