Is the value of `this` pointer constant during the object's lifetime?

Is the value of this pointer guaranteed to be constant during a lifetime of a particular object?

Yes.

As user Aconcagua puts it: the value of this pointer always is the value of the address of the object on which the function was called on1. So the question is equivalent with:

Can an object change its memory address over life time?

This is not possible, by definition of lifetime2. The lifetime of an object begins when or after its storage is obtained and ends before of when it is released.


1) [class.this]/1

In the body of a non-static ([class.mfct]) member function, the keyword this is a prvalue whose value is a pointer to the object for which the function is called.

2) [basic.life]/1 (emphasis mine)

The lifetime of an object or reference is a runtime property of the object or reference. A variable is said to have vacuous initialization if it is default-initialized and, if it is of class type or a (possibly multi-dimensional) array thereof, that class type has a trivial default constructor. The lifetime of an object of type T begins when:

  • storage with the proper alignment and size for type T is obtained, and
  • its initialization (if any) is complete (including vacuous initialization) ([dcl.init]), except that if the object is a union member or subobject thereof, its lifetime only begins if that union member is the initialized member in the union ([dcl.init.aggr], [class.base.init]), or as described in [class.union].

The lifetime of an object o of type T ends when:

  • if T is a non-class type, the object is destroyed, or
  • if T is a class type, the destructor call starts, or
  • the storage which the object occupies is released, or is reused by an object that is not nested within o ([intro.object]).

An object has a region of storage. this points there.

[intro.object]/1

An object occupies a region of storage in its period of construction ([class.cdtor]), throughout its lifetime, and in its period of destruction ([class.cdtor]).