decltype(auto) vs auto&& to perform generic handling of function's return type
When using auto&& to handle a function returning an lvalue: int func() { int v=42; return v; } auto && v = func(); What are the consequences of treating v as a reference instead of an lvalue? Do these consequences justify the use of decltype(auto) instead of auto&& to perform generic handling of function's return type? auto&& is already optimal for capturing function return values, such that the differences of decltype(auto) can only be disadvantages. In your example, lifetime extension is applied to the otherwise-temporary object returned from the function. This causes it to behave