[Bug c++/115987] False "possibly dangling reference" false positive when having an extra template parameter
mpolacek at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Thu Jul 18 17:18:13 GMT 2024
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115987
--- Comment #12 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
(In reply to Dan Urosu from comment #11)
> 1) "We don't analyze the body of the function"
> unwrap_1 and unwrap_2 are functionally equivalent. Yet only unwrap_2
> triggers the warning.
But that's my point. We don't know that they are functionally equivalent, but
we do see that the second argument of unwrap_2 is a reference to a temporary,
and the function returns a reference. The assumption is that the function does
something with the temporary, possibly returning a reference to it, which is
bad.
> 2) If the unwrap_2 is called from a macro, then the pragma suppression does
> not work.
>
> If the #pragma GCC diagnostic ignored "-Wdangling-reference" would work in
> cas (2) above, we could use it as a band-aid solution.
Full testcase, please? (Sorry if I missed it.)
> PS. Also worth mentioning, if you write the non-cost equivalent of the
> unwrap_2 template function
> "T& unwrap_2(Wrapper<T>& r, FUNC&&) ", you don't get the warning.
Right, that's how it works.
More information about the Gcc-bugs
mailing list