C++ Logo

std-proposals

Advanced search

Re: [std-proposals] p3039r1 proxy temporary objects

From: Marcin Jaczewski <marcinjaczewski86_at_[hidden]>
Date: Fri, 20 Feb 2026 20:48:46 +0100
pt., 20 lut 2026 o 20:38 Andre Kostur via Std-Proposals
<std-proposals_at_[hidden]> napisaƂ(a):
>
> On Fri, Feb 20, 2026 at 11:04 AM Jason McKesson via Std-Proposals
> <std-proposals_at_[hidden]> wrote:
> >
> > On Fri, Feb 20, 2026 at 1:39 PM Marcin Jaczewski via Std-Proposals
> > If it uses an existing `operator->`, then there's no problem.
> > `operator->` cannot return a temporary; it must return a pointer. So
>
> Nitpick (possibly just phrasing): `operator->` doesn't have to return
> a pointer, it only has to return something that `->` can be applied
> to. Which might be a proxy object, and that proxy object's
> `operator->` returns a pointer. Once it gets to a raw pointer, then
> [expr.ref]{2} takes over.

Yes, exactly and this is problem as it always `operator->` between
last temporary proxy and last pointer and this break possibility of
life extend of temporary proxy object as:

```
const auto& x = foo{}.self_ptr()->x;
//same as user defined
const auto& x = foo{}->x;
// foo do not get life time extended
```

And even worse we do not have proper && references there as the last
operation needs work on pointers and it can't point to references.

But `operator*` does not have this problem.

> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals

Received on 2026-02-20 19:49:02