C++ Logo

std-proposals

Advanced search

Re: [std-proposals] this return type

From: Lénárd Szolnoki <cpp_at_[hidden]>
Date: Sun, 09 Apr 2023 11:18:41 +0100
On Sun, 2023-04-09 at 11:18 +0200, Jan Schultke wrote:
> > Shouldn't compilers optimise this similarly to cache the vtable
> > pointer?
>
> > https://godbolt.org/z/zxj7nxr9s
>
> No, the implementation cannot cache the vtable pointer because the
> vtable pointer can change between member function calls. This happens
> if the member function explicitly ends and begins the lifetime of
> this
> inside of the function.

Do you mean by storage reuse? Because I don't think it's allowed for
`b` to refer to the newly created object, unless if it has the same
exact type.

https://eel.is/c++draft/basic.life#8

Cheers,
Lénárd

Received on 2023-04-09 10:18:46