[Bug c++/25231] Compiler error for copy constructor with non const input
pinskia at gcc dot gnu dot org
gcc-bugzilla@gcc.gnu.org
Fri Dec 2 21:15:00 GMT 2005
------- 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
More information about the Gcc-bugs
mailing list