2

In article "Move semantics and rvalue references in C++11" by Alex Allain, I read:

Notice, by the way, that holding on to a const reference to a temporary object ensures that the temporary object isn't immediately destructed. This is a nice guarantee of C++, but it is still a temporary object, so you don't want to modify it.

Of course I know that a const reference is not, nor behaves like, a shared_ptr (which one would hope, reading "holding on [...] the temporary object isn't immediately destructed"), but I wasn't able to find any more reference.
So the question is: How is this addressed in the standard?

Grijesh Chauhan
  • 55,177
  • 19
  • 133
  • 197
Stefano Falasca
  • 8,337
  • 1
  • 14
  • 23
  • What do you mean "how is this addressed"? Are you asking what C++ does with temporaries bound to ref-to-non-`const`? Or what? – Lightness Races in Orbit Jul 23 '13 at 17:39
  • The "duplicate" doesn't mention extending the temporary's lifetime by binding to a reference; it only covers the normal lifetime of a temporary. See C++11 12.2/5 for details, but the summary is just what the article says: if a temporary is used directly to initialise a reference (which must be `const`), then its lifetime is extended to match that of the reference. – Mike Seymour Jul 23 '13 at 17:44

0 Answers0