This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: c++/8910: Incorrect code generation when returning class by value
- From: bangerth at dealii dot org
- To: gcc-bugs at gcc dot gnu dot org, gcc-prs at gcc dot gnu dot org, lgandhi at peerless dot com, nobody at gcc dot gnu dot org
- Date: 12 Dec 2002 15:27:45 -0000
- Subject: Re: c++/8910: Incorrect code generation when returning class by value
- Reply-to: bangerth at dealii dot org, gcc-bugs at gcc dot gnu dot org, gcc-prs at gcc dot gnu dot org, lgandhi at peerless dot com, nobody at gcc dot gnu dot org, gcc-gnats at gcc dot gnu dot org
Synopsis: Incorrect code generation when returning class by value
State-Changed-From-To: open->closed
State-Changed-By: bangerth
State-Changed-When: Thu Dec 12 07:27:45 2002
State-Changed-Why:
This is not a bug. In your conversion operator, you
generate an unnamed object B(1234), which will then be
assigned to the return value. However, you made the copy
constructor of B explicit. The standard says:
An explicit constructor constructs objects just like non-explicit con-
structors, but does so only where the direct-initialization syntax
(_dcl.init_) or where casts (_expr.static.cast_, _expr.cast_) are
explicitly used.
Assigning to the return value does not happen with an
explicit syntax, so the copy constructor cannot be used.
That's it. The rest is just that gcc finds a conversion
sequence that does what you want. Upshot: when you declare
a class with an "explicit" copy constructor, you may not
use it as a return value for functions that return by
value (rather than by reference, for example).
http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=8910