C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Relocation in C++

From: Edward Catmur <ecatmur_at_[hidden]>
Date: Tue, 3 May 2022 08:10:19 +0100
On Tue, 3 May 2022, 05:31 Thiago Macieira via Std-Proposals, <
std-proposals_at_[hidden]> wrote:

> On Monday, 2 May 2022 13:50:22 PDT Lénárd Szolnoki via Std-Proposals wrote:
> > "It is implementation-defined whether the lifetime of a parameter ends
> > when the function in which it is defined returns or at the end of the
> > enclosing full-expression."
>
> In other words, this function could return a dangling pointer?
>
> const char *f(std::string s)
> {
> return s.begin();
> }
>
> that's messed up.
>

It doesn't feel like that to me; the variable is clearly scoped to the
function call. If you want a temporary with full expression lifetime, use
pass by rvalue reference.

Received on 2022-05-03 07:10:33