This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/25231] Compiler error for copy constructor with non const input
- From: "pinskia at gcc dot gnu dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 2 Dec 2005 21:14:59 -0000
- Subject: [Bug c++/25231] Compiler error for copy constructor with non const input
- References: <bug-25231-11809@http.gcc.gnu.org/bugzilla/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Comment #3 from pinskia at gcc dot gnu dot org 2005-12-02 21:14 -------
(In reply to comment #2)
> I really don't think that the reply addresses the question. If a function
> returns an object it has to call a copy constructor. This code compiles if the
> copy constructor is declared as
> t1(const t1& tr);
> but fails if declared as
> t1(t1& tr);
> I don't see how the reply deals with this issue.
Yes the code compiles fine if the copy constructor is
t1(const t1& tr);
because you can bind a non lvalue to a const reference.
I had forgot to say that.
This is just like:
class t {};
t f(void);
void h(t &);
void g(void)
{
h(f());
}
which fails as you cannot bind a temporary to a reference, only to a constant
reference, so if you declare h like:
void h(const t&);
It will work.
--
pinskia at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25231