https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115987

--- Comment #13 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Dan Urosu from comment #7)
> Why does not warn for unwarp_1?
> The mere addition of an unused template parameter triggers this warning.

No it doesn't. Calling the function with a temporary triggers the warning.

unwrap_1(w) has no temporary involved. unwrap_2(w, 1) creates a temporary of
type int.

What matters is calling the function with a temporary and returning a const
reference which the compiler thinks *might* bind to the temporary.

Your T& example doesn't warn because a non-const reference cannot bind to a
temporary, so there's no chance it is a dangling reference to the temporary
argument.

Reply via email to