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.