https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115987
--- Comment #20 from Jonathan Wakely <redi at gcc dot gnu.org> --- (In reply to Dan Urosu from comment #19) > (In reply to Marek Polacek from comment #18) > > But is unwrap_1 called in such a way that 'r' binds to a temporary? The answer is no, it's being called with an lvalue. > > Did you mean 'u' binds to a temporary? No. Is the argument to unwrap_1 a temporary. > In this case r1 is a temporary object No it isn't, it's an lvalue. The purpose of -Wdangling-reference is to warn about temporaries passed in to functions that then return a reference to the temporary. It's not designed to warn about the case where you return a reference to a local object. -Wreturn-local-addr should warn about that case though. > and a reference to its inner value is > returned by the function. > The warning might have not been intended for this case, but all I'm saying > is that this example shows a very common case of a dangling reference. (and > is not flagged) That's what -Wreturn-local-addr is for.