This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Method stack return usage has incorrect GCC error
- From: Jonathan Wakely <jwakely dot gcc at gmail dot com>
- To: Arthur Schwarz <aschwarz1309 at att dot net>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Fri, 6 Jul 2012 18:28:04 +0100
- Subject: Re: Method stack return usage has incorrect GCC error
- References: <1341595314.28363.YahooMailRC@web181301.mail.ne1.yahoo.com>
On 6 July 2012 18:21, Arthur Schwarz wrote:
>
> In the following example I think that gcc has incorrectly generated an "error:
> no matching function for call to ‘derived::fnc4(derived)’" error for "
> b1.fnc4(b1.fnc1());". My guess is that gcc does not handle a function return
> returning an object on the stack used as an argument to a function. If this is
> incorrect, on my part, would someone explain why I am wrong.
Your function returns an rvalue which cannot bind to a non-const
lvalue-reference.
i.e. an lvalue reference such as "derived&" cannot bind to a
temporary, such as the return value of your function.
> Not that this is of the slightest concern to GCC (nor should it be), MSVC++ 2010
> does not produce a diagnostis.
This is a well-known bug^W feature of MSVC, I think there's some
switch to make it follow the standard and disable it.