C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Contradiction about this parameter in the C++ standard

From: Edward Catmur <ecatmur_at_[hidden]>
Date: Tue, 19 Apr 2022 12:35:01 +0100
On Tue, 19 Apr 2022 at 12:27, <language.lawyer_at_[hidden]> wrote:

> On 19/04/2022 14:16, Jens Maurer wrote:
> > On 19/04/2022 11.57, Edward Catmur via Std-Proposals wrote:
> >> On Tue, 19 Apr 2022 at 09:46, <language.lawyer_at_[hidden] <mailto:
> language.lawyer_at_[hidden]>> wrote:
> >>
> >> On 19/04/2022 11:24, Edward Catmur wrote:
> >
> >> > Yes, I think that's where the connection is made. So that's
> possibly a
> >> > derived class object, and it's worth explaining where the this
> pointer with
> >> > type pointer to base gets its value from.
> >>
> >> IDK, why/when having «the object for which function is invoked»
> meaning «the result of the object expression» and overloading the
> definition of `this` with «or to its base class subobject» is useful?
> >>
> >>
> >> What else could "the object for which function the is invoked" mean
> other than "the result of the object expression"?
> >
> > Consider this example:
> >
> > x.f();
> >
> > If f is a member function of a base class, you need to convert
> > "x" to the base class type. In most implementations, if the base
> > class is not the first one in your base-specifier, this means
> > adjusting the address that "x" represents by the offset of the
> > base subobject inside the "x".
> >
> > This is what the standard wants to capture, and that's why
> > the value of "this" is not just the value of the object
> > expression.
>
> `this` will point to the corresponding subobject, Edward's proposal is to
> always mean "the result of the object expression" by "the object for which
> function the is invoked", but change `this` definition to say that it is
> not always points at "the object for which function the is invoked".
>

Right. Currently I can't see "the object for which the function is invoked"
defined anywhere, so the natural reading is "the result of the object
expression".

So (by my reading) either the Standard should explicitly define "the object
for which the function is invoked" as possibly a base class subobject of
"the result of the object expression", as appropriate depending on the
function invoked, or it should (explicitly or implicitly) define "the
object for which the function is invoked" as precisely "the result of the
object expression", and point this to the appropriate base class subobject
for the function invoked.

Received on 2022-04-19 11:35:13