[Bug c++/115987] False "possibly dangling reference" false positive when having an extra template parameter
redi at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Thu Jul 18 17:18:43 GMT 2024
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.
More information about the Gcc-bugs
mailing list