c++: P0847R7 (deducing this) - initial functionality. [PR102609]
[official-gcc.git] / gcc / testsuite / g++.dg / cpp23 / explicit-obj-by-value2.C
blobb8e8e73dfafa3062e21254f4a0d192fd8db091ad
1 // P0847R7
2 // { dg-do run { target c++23 } }
4 // conversion of the implicit object argument to an xobj parameter
5 // using a user defined conversion or converting constructor
6 // when calling by value xobj member functions
8 // see explicit-obj-by-value1.C for details on this test
10 using uintptr_t = __UINTPTR_TYPE__;
11 inline constexpr uintptr_t magic = 42;
13 struct S;
15 struct FromS {
16   uintptr_t _v;
17   FromS(S);
20 struct S {
21   operator uintptr_t() const {
22     return magic;
23   }
24   uintptr_t f(this uintptr_t n) {
25     return n;
26   }
27   uintptr_t g(this FromS from_s) {
28     return from_s._v;
29   }
32 FromS::FromS(S) : _v(magic) {}
35 int main() 
37   S s0{};
38   S s1{};
39   // prevent (absurdly improbable) bogus failures
40   S& s = magic != (uintptr_t)(&s0) ? s0 : s1;
42   uintptr_t const ret0 = s.f();
43   // check for reinterpretation of the object argument
44   if (ret0 == (uintptr_t)(&s))
45     __builtin_abort ();
46   // check for a bugged conversion
47   if (ret0 != magic)
48     __builtin_abort ();
50   uintptr_t const ret1 = s.g();
51   // check for reinterpretation of the object argument
52   if (ret1 == (uintptr_t)(&s))
53     __builtin_abort ();
54   // check for a bugged conversion
55   if (ret1 != magic)
56     __builtin_abort ();