This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/49974] New: 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:23:30 +0000
- Subject: [Bug c++/49974] New: missing warning for indirectly returning reference to local/temporary
- Auto-submitted: auto-generated
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49974
Summary: missing warning for indirectly returning reference to
local/temporary
Product: gcc
Version: 4.7.0
Status: UNCONFIRMED
Keywords: diagnostic
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: redi@gcc.gnu.org
Although probably not easy, it would be useful to get warnings from this code
which creates dangling references:
struct X { };
inline const X& f(const X& r) { return r; }
const X& g()
{
X x;
return f(x); // !!!
}
const X& h()
{
return f(X()); // !!!
}
Another case involves a reference as a member of a class:
struct Y {
Y(int& i) : r(i) { }
int& r;
};
Y f()
{
int i=0;
return Y(i);
}