[Bug c++/102223] no warning when calling member function on dangling reference

redi at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Wed Sep 8 10:24:21 GMT 2021


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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=96780

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Your compiler explorer link doesn't enable optimizations. There's no way G++
can warn without optimization (specifically, without inlining). The std::move
call is an opaque function that returns a reference, which might have nothing
whatsoever to do with the function argument, so the reference it returns could
be valid.

With inlining, in theory it would be possible to diagnose the invalid access,
but other compilers don't do it either. It would be nice, but I'm not sure it's
likely to happen any time soon. GCC doesn't even get it right in constexpr
contexts, see PR 70331 and the linked bugs in the See Also field.

PR 96780 comment 2 could potentially help for the specific case of std::move,
but not the general case.


More information about the Gcc-bugs mailing list