C++ Logo

std-proposals

Advanced search

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

From: Anoop Rana <ranaanoop986_at_[hidden]>
Date: Mon, 18 Apr 2022 22:15:16 +0530
There seems to be a contradiction between the two statements from the
standard as described below:

>From class.this#1 <https://timsong-cpp.github.io/cppwp/n4659/class.this#1>:
> In the body of a non-static member function, the keyword this is a *prvalue
expression* whose value is the address of the object for which the function
is called...

But in the same document at expr.call#4
<https://timsong-cpp.github.io/cppwp/n4659/expr.call#4>:

> When a function is called, each parameter ([dcl.fct]) shall be
initialized ([dcl.init], [class.copy], [class.ctor]) with its corresponding
argument. *If the function is a non-static member function, the `this`
parameter of the function shall be initialized* with a pointer to the
object of the call, converted as if by an explicit type conversion...

---
Now we know that if we have a function parameter named `var`, then the
value category of that parameter `var`(as an expression) is an *lvalue*.
Thus, reading the 2nd quoted statement above(that implies that a non-static
member function has a `this` parameter), the same should apply to the
`this` parameter. In particular, if `this` is indeed a parameter of a
non-static member function then its value category(as an expression) should
be *lvalue* which contradicts with the first quoted statement that says
`this` is a *prvalue expression.*
The problem comes due to the use of the phrase "`this` parameter" in the
second quoted statement above. So how should this be rectified given that
the contradiction follows naturally from the two quoted statements.

Received on 2022-04-18 16:45:28