C++ Logo


Advanced search

Subject: Re: is this valid static const reference
From: Thiago Macieira (thiago_at_[hidden])
Date: 2020-07-08 20:49:34

On Wednesday, 8 July 2020 17:55:09 PDT spsaxena via Std-Discussion wrote:
> Foo dup() { printf("dup foo %p\n", this); return *this; }
> };
> static const Foo& tempPath(Foo().dup());

Yes, that's valid. Foo::dup() returns an xvalue, so that gets lifetime-
extended until program termination and that object is stored in "tempPath".

Suggestion: drop the reference and save one indirection.

Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
   Software Architect - Intel System Software Products

STD-DISCUSSION list run by std-discussion-owner@lists.isocpp.org

Older Archives on Google Groups