Date: Fri, 20 Feb 2026 20:20:39 +0100
pt., 20 lut 2026 o 20:03 Andre Kostur <andre_at_[hidden]> napisał(a):
>
> Thanks for the pointer, you are correct: [class.temporary] paragraph
> 6.4 documents that.
>
> This wasn't an interaction that I'd anticipated. At first glance this
> seems to be a desirable side-effect. And part of the point of this
> paper is that folk shouldn't have to write their own operator-> in
> most cases (though it doesn't prevent one from doing so if there's a
> reason to).
>
Overall I point this out because `->` and having a proxy is hard to do,
example: https://github.com/jbeder/yaml-cpp/issues/977
I encountered this bug too.
If this behavior will be standardized then `->` becomes a lot more
useful and powerful. I was only worried that standard wording could enforce
different lifetime (more inline with user defined `->`) of this
variable making it harder to use.
> On Fri, Feb 20, 2026 at 10:47 AM Marcin Jaczewski
> <marcinjaczewski86_at_[hidden]> wrote:
> >
> > pt., 20 lut 2026 o 19:42 Andre Kostur <andre_at_[hidden]> napisał(a):
> > >
> > > It wouldn't though: foo would't be binding to a temporary, it would be
> > > binding to the result of doing ".member" on the temporary.
> > >
> >
> > I recall there is rule when you bind to a member then the whole object
> > get lifetime expanded.
> > Consider this code:
> >
> > ```
> > #include <cstdio>
> >
> > struct bar {
> > bar () { std::puts("start"); }
> > ~bar () { std::puts("end"); }
> >
> > int i;
> >
> > };
> >
> >
> > bar foo()
> > {
> > return {};
> > }
> >
> > int main() {
> > const auto& i = foo().i;
> > std::puts("work");
> > }
> > ```
> >
> > its print:
> >
> > ```
> > start
> > work
> > end
> > ```
> >
> > https://godbolt.org/z/bheoTd1n3
> >
> > > On Fri, Feb 20, 2026 at 10:39 AM Marcin Jaczewski via Std-Proposals
> > > <std-proposals_at_[hidden]> wrote:
> > > >
> > > > Paper suggests rewriting `ptr->meber` by `(*ptr).member`.
> > > >
> > > > But this creates an interesting case, new `->` created this way will
> > > > have capabilities impossible compared to manually written `->`.
> > > >
> > > > Consider example:
> > > > ```
> > > > const auto& foo = ptr->member;
> > > > ```
> > > > and `ptr` that has a `*` returning proxy value.
> > > > With this rewrite, the lifetime of the proxy object will be expanded
> > > > to the lifetime of the `foo` reference.
> > > > Using user defined `->` you can't in anyway do this as this operator
> > > > is required to return pointer and not value (as it will call nested of `->`).
> > > >
> > > > This is expected behavior? If yes then maybe we should
> > > > discourage of further use of user defined `->` operator?
> > > > --
> > > > Std-Proposals mailing list
> > > > Std-Proposals_at_[hidden]
> > > > https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>
> Thanks for the pointer, you are correct: [class.temporary] paragraph
> 6.4 documents that.
>
> This wasn't an interaction that I'd anticipated. At first glance this
> seems to be a desirable side-effect. And part of the point of this
> paper is that folk shouldn't have to write their own operator-> in
> most cases (though it doesn't prevent one from doing so if there's a
> reason to).
>
Overall I point this out because `->` and having a proxy is hard to do,
example: https://github.com/jbeder/yaml-cpp/issues/977
I encountered this bug too.
If this behavior will be standardized then `->` becomes a lot more
useful and powerful. I was only worried that standard wording could enforce
different lifetime (more inline with user defined `->`) of this
variable making it harder to use.
> On Fri, Feb 20, 2026 at 10:47 AM Marcin Jaczewski
> <marcinjaczewski86_at_[hidden]> wrote:
> >
> > pt., 20 lut 2026 o 19:42 Andre Kostur <andre_at_[hidden]> napisał(a):
> > >
> > > It wouldn't though: foo would't be binding to a temporary, it would be
> > > binding to the result of doing ".member" on the temporary.
> > >
> >
> > I recall there is rule when you bind to a member then the whole object
> > get lifetime expanded.
> > Consider this code:
> >
> > ```
> > #include <cstdio>
> >
> > struct bar {
> > bar () { std::puts("start"); }
> > ~bar () { std::puts("end"); }
> >
> > int i;
> >
> > };
> >
> >
> > bar foo()
> > {
> > return {};
> > }
> >
> > int main() {
> > const auto& i = foo().i;
> > std::puts("work");
> > }
> > ```
> >
> > its print:
> >
> > ```
> > start
> > work
> > end
> > ```
> >
> > https://godbolt.org/z/bheoTd1n3
> >
> > > On Fri, Feb 20, 2026 at 10:39 AM Marcin Jaczewski via Std-Proposals
> > > <std-proposals_at_[hidden]> wrote:
> > > >
> > > > Paper suggests rewriting `ptr->meber` by `(*ptr).member`.
> > > >
> > > > But this creates an interesting case, new `->` created this way will
> > > > have capabilities impossible compared to manually written `->`.
> > > >
> > > > Consider example:
> > > > ```
> > > > const auto& foo = ptr->member;
> > > > ```
> > > > and `ptr` that has a `*` returning proxy value.
> > > > With this rewrite, the lifetime of the proxy object will be expanded
> > > > to the lifetime of the `foo` reference.
> > > > Using user defined `->` you can't in anyway do this as this operator
> > > > is required to return pointer and not value (as it will call nested of `->`).
> > > >
> > > > This is expected behavior? If yes then maybe we should
> > > > discourage of further use of user defined `->` operator?
> > > > --
> > > > Std-Proposals mailing list
> > > > Std-Proposals_at_[hidden]
> > > > https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
Received on 2026-02-20 19:20:54
