Date: Fri, 20 Feb 2026 19:47:00 +0100
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
>
> 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 18:47:14
