Which standard wording tells us that ref-to-const temporary lifetime extension only “works once”?

You’re almost right. This behaviour actually comes from the function call specifically, not because of any sort of “only works once” rule.

Here’s the wording for the whole lifetime extension “feature”, with the pertinent rule emphasised in bold:

[C++11: 12.2/5]: [..] The temporary to which the reference is bound or the temporary that is the complete object of a subobject to which the reference is bound persists for the lifetime of the reference except:

  • [..]
  • A temporary bound to a reference parameter in a function call (5.2.2) persists until the completion of the full-expression containing the call.
  • [..]

Leave a Comment