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: unassig...@gcc.gnu.org ReportedBy: r...@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); }