On 4 August 2011 11:31, LIM Fung-Chai wrote: > Hi, > > On Thu, Aug 4, 2011 at 5:29 PM, Miles Bader <mi...@gnu.org> wrote: >> Jonathan Wakely <jwakely....@gmail.com> writes: >>>> "g++ -Wall -Wextra ..." should flag a warning on the following code >>>> but does not. >>> >>> Thanks for the apology, but it should still be reported to bugzilla >>> not to this list. > > I was hoping someone could submit a bugzilla report. I don't want to > create an account which I may never use again.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49974 >> >> BTW, it should only warn if given -Weffc++, right? > > -Weffc++ does not catch the dangerous error in my code. -Wall caught > another Item21 error somewhere else in my code: > > std::vector<XYZ*>& > get_XYYs() > { > std::vector<XYZ*> result; > return result; > } > > I notice -Weffc++ produces more warnings on my code, but -Wall knows > about Item21. Both -Weffc++ and -Wall only see get_XYZs() as an > Item21 violation but not get_XYZ_data() which returns the local > variable as a reference in an std::pair. Because -Weffc++ issues warnings about style guidelines (specifically, Items 11, 12, 14, 15, 23 from Effective C++ and Items 6 and 67 from More Effective C++) that not everyone agrees with in all cases. Item 21 is about correctness, not style, returning a dangling reference always warrants a warning.