This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/18113] compiler allows 2 copy constructors
- From: "reichelt at gcc dot gnu dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 26 Oct 2004 20:34:07 -0000
- Subject: [Bug c++/18113] compiler allows 2 copy constructors
- References: <20041022164853.18113.profvonsully@yahoo.com>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Additional Comments From reichelt at gcc dot gnu dot org 2004-10-26 20:34 -------
Here's a detailed explanation of the second example:
You are calling the function "void HandleObject(TObject toj);" as follows:
"HandleObject( GetAnObject() );"
To do this you need a copy constructor to copy the result of
"GetAnObject()" into "toj".
The only copy constructor that is available is "TObject(const rObject)"
which is essentially "TObject(TObject&)" and not "TObject(const TObject&)"
as one might think (see comment #2).
However, "TObject(TObject&)" can only take an lvalue (something that can
be modified) as argument, but "GetAnObject()" only provides an lvalue
(which cannot be modified). Therefore, gcc correctly complains that it
cannot find a suitable copy constructor.
This is a bug in your code and not in gcc.
Note, that the compiler is allowed to optimize away the copy constructor.
Nevertheless, it has to check whether the copy constructor is present.
Alas, many compilers forgot to check this.
--
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18113