This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Strange use of Copy Constructor of gcc version 2.95.1 19990816 (release)


> 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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]