2 // { dg-do run { target c++23 } }
4 // conversion of the implicit object argument to an xobj parameter
5 // when calling by value xobj member functions
7 // The initial implementation of xobj member functions incorrectly did not
8 // convert the implicit object argument when binding to the xobj
9 // parameter. In spite of this, it did correctly check to see if such a
10 // conversion would be valid, thus no diagnostic would be emitted when a
11 // conversion was valid, but instead of applying the conversion, the
12 // argument would silently be reinterpreted as the type of the parameter.
14 // This is why we use uintptr_t for the value in S and compare the result
15 // of f to &s, we want to test for simple reinterpretation of the
16 // argument. To accurately test for this we make sure to use an object
17 // that has a different address than the value of our magic number. It's
18 // an impossibly improbable edge case but it's trivial to work around. We
19 // still compare against both the address of s and the magic number so we
20 // can additionally test for bugged conversions, while also
21 // differentiating that case from reinterpretation of the argument.
23 using uintptr_t = __UINTPTR_TYPE__;
24 inline constexpr uintptr_t magic = 42;
28 uintptr_t f(this S self) {
37 // prevent (absurdly improbable) bogus failures
38 S& s = magic != (uintptr_t)(&s0) ? s0 : s1;
40 uintptr_t const ret = s.f();
41 // check for reinterpretation of the object argument
42 if (ret == (uintptr_t)(&s))
44 // check for a bugged conversion