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 08:37:47 +0100
On Tue, 19 Apr 2022 at 03:22, <language.lawyer_at_[hidden]> wrote:

> On 18/04/2022 23:23, Edward Catmur wrote:
> > On Mon, 18 Apr 2022 at 21:13, <language.lawyer_at_[hidden]> wrote:
> >
> >> On 18/04/2022 22:57, Edward Catmur wrote:
> >>> I suppose that paragraph <
> https://eel.is/c++draft/expr.call#7.sentence-4>
> >> (and
> >>> the following Note) should be struck entirely.
> >> I'd say then we will not know which object [expr.prim.this]/1 speaks
> about
> >> (Ā«The keyword `this` names a pointer to the object for which an implicit
> >> object member function is invokedĀ»)
> >>
> >
> > "the object for which an implicit object member function is invoked"
> seems
> > clear enough; per [expr.call]/2 it's the object expression on the LHS of
> > the postfix expression (before the '.', '->', '.*' or '->*').
>
> If it is a base-class function, the object is the corresponding base class
> subobject, isn't it?
>

Yes, but that's a problem with [expr.prim.this]/1; you can't have a pointer
of base type pointing to an object of derived type. So that subclause is
also defective, and should have appended ", or to its base class subobject,
as appropriate".

As for [expr.call]/7, there's no need to specify *how* the implementation
is expected to come up with the value of the `this` pointer (although it
could be a Note).

e.g.:

--- a/source/expressions.tex
+++ b/source/expressions.tex
@@ -1198,7 +1198,8 @@
 \indextext{\idxcode{this}}%
 The keyword \keyword{this} names a pointer to the object for which an
implicit object member
 function\iref{class.mfct.non.static} is invoked or a non-static data member's
-initializer\iref{class.mem} is evaluated.
+initializer\iref{class.mem} is evaluated, or to its base class
+subobject\iref{class.derived}, as appropriate.

 \pnum
 The \defnadj{current}{class} at a program point is
@@ -3197,12 +3198,12 @@
 int x = f<int>(); // error: no argument for second
function parameter
 \end{codeblock}
 \end{example}
-If the function is an implicit object member
-function, the \keyword{this} parameter of the function\iref{expr.prim.this}
-is initialized with a pointer to the object of the call, converted
-as if by an explicit type conversion\iref{expr.cast}.
 \begin{note}
-There is no access or ambiguity checking on this conversion; the access
+If the function is an implicit object member
+function, within the function the \keyword{this}\iref{expr.prim.this}
+names a pointer to the object of the call or to its base class subobject
+as appropriate, as if converted by an explicit type conversion\iref{expr.cast}.
+There is no access or ambiguity checking on this (notional)
conversion; the access
 checking and disambiguation are done as part of the (possibly implicit)
 class member access operator.
 See~\ref{class.member.lookup}, \ref{class.access.base},

Received on 2022-04-19 07:37:59