This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: g++ 2.5.2 does not catch reference to local variable error.


On 4 August 2011 03:30, LIM Fung-Chai <lim.fung.chai@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);
}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]