lundi 20 juin 2016

Why can non-parameter references bind to xvalues?

I was reading the answer to Overloading on R-value references and code duplication. It explains potential dangers to returning rvalue references from functions, in particular, that assigning the result to an auto &&, as is done automatically in range-based for loops, could lead to a dangling reference. My question is, couldn't this potential bug be preempted by disallowing references from binding to xvalues (except when passing function arguments)? Is there ever a case where it is appropriate to bind a local reference variable to an xvalue?

Aucun commentaire:

Enregistrer un commentaire