This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: Strange use of Copy Constructor of gcc version 2.95.1 19990816 (release)
- To: Thomas dot Rudlof at mchp dot siemens dot de
- Subject: Re: Strange use of Copy Constructor of gcc version 2.95.1 19990816 (release)
- From: "Martin v. Loewis" <martin at loewis dot home dot cs dot tu-berlin dot de>
- Date: Sun, 5 Mar 2000 10:56:30 +0100
- CC: gcc-bugs at gcc dot gnu dot org
- References: <199909160908.LAA03911@schuette.mchp.siemens.de>
> So, since P(const P&) is not declared any more, it seems that the
> compiler does not allow now, what has happened without any warnings in
> the previous example.
Thanks for your bug report. It's not a bug in the compiler, but a bug
in your code. When you write
P p=&i;
you are asking for a copy-initialization, whereas
P p(&i);
would have been a direct-initialization. In a copy-initialization, a
temporary of type P is created, which is then used to initialize p,
using a copy constructor. Since the only available copy constructor is
P(P& p);
the program is ill-formed - you cannot bind a temporary (an r-value)
to a non-const referece.
If you question this line of reasoning, please discuss it in one of
the public C++ fora first, eg. comp.lang.c++.moderated, or
comp.std.c++.
Regards,
Martin