On 4 August 2011 03:30, LIM Fung-Chai <lim.fung.c...@gmail.com> wrote: > Hi, > > "g++ -Wall -Wextra ..." should flag a warning on the following code > but does not. > > std::pair<int, const XYZ&> > get_XYZ_data() > { > XYZ result; > return std::pair<int, const XYZ&>(1, result); > } > > This is a violation of Scott Meyer's "Effective C++" Item 21 "Don't > try to return a reference when you must return an object." GCC > version 4.5.2 on Kubuntu 11.04 does not issue a warning. > > I apologize for not subscribing to the mailing list or submitting via > GCC Buzilla.
Thanks for the apology, but it should still be reported to bugzilla not to this list. Your example can be reduced to struct XYZ { }; XYZ& f(XYZ& r) { return r; } XYZ& get_XYZ_data() { XYZ result; return f(result); }