http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53855
Bug #: 53855 Summary: Emitting a warning for some dangling references. Classification: Unclassified Product: gcc Version: tree-ssa Status: UNCONFIRMED Severity: enhancement Priority: P3 Component: tree-optimization AssignedTo: unassig...@gcc.gnu.org ReportedBy: e...@edrosten.com A dangling reference is created in the following code: struct IntRef { IntRef(const int& v_) :v(v_) { } const int& v; double get() const { return v; } }; struct BRef { BRef(const IntRef& v_) :v(v_) { } const IntRef& v; double get() const { return v.get(); } }; double test(const int& a) { const BRef c(a); return c.get(); } After the first stage of copy propagation, the representation of test is (from test.cc.029t.copyprop1): ;; Function double test(const int&) (_Z4testRKi, funcdef_no=8, decl_uid=2230, cgraph_uid=8) double test(const int&) (const int & a) { const struct IntRef & c$v; const struct IntRef & D.2286; int D.2284; const int & D.2283; double D.2282; const struct BRef c; const struct IntRef D.2251; <bb 2>: D.2251.v = a_1(D); D.2251 ={v} {CLOBBER}; D.2283_9 = D.2251.v; D.2284_10 = *D.2283_9; D.2282_11 = (double) D.2284_10; return D.2282_11; } at which point is is quite obvious that D.2251 is used after it is CLOBBER'd. Is it possible to add a feature to generate a warning in this case? I'm using gcc version r189256 from SVN, but things are much the same in 4.7.