This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/49974] missing warning for indirectly returning reference to local/temporary
- From: "redi at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Thu, 4 Aug 2011 12:40:39 +0000
- Subject: [Bug c++/49974] missing warning for indirectly returning reference to local/temporary
- Auto-submitted: auto-generated
- References: <bug-49974-4@http.gcc.gnu.org/bugzilla/>
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49974
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Severity|normal |enhancement
--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> 2011-08-04 12:40:15 UTC ---
Maybe related, but not the same. PR986 involves creating a temporary and
binding the reference to it, that should be easier to warn about. Here's a
similar case to PR986 where a reference member is dangling after the
constructor, which we fail to warn about:
struct Y {
Y(int local) : ref(local) { }
int& ref;
};
That, and the example in 986, should be easy to warn about. When the reference
is bound we can know if the initializer is local/temporary.
This PR is different, the references passed to f and Y::Y are valid during
those calls. The reference only becomes invalid when it escapes from the
function that declares the local variable. This requires some more complex
analysis, only possible if the bodies of f and Y::Y are visible, and maybe only
possible with optimization enabled so inlining happens.