This is the mail archive of the gcc-help@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]
Other format: [Raw text]

Re: copy ctor not called


On Thursday 07 July 2005 02:04 pm, Eljay Love-Jensen wrote:
> Hi Jeroen,
>
> >According to your statement they are wrong.
>
> Please re-read my statement.  My statement does not contradict what you
> cited from C++ Primer.
>
> What is being elided is the assignment operator, not the copy constructor. 
> The copy constructor is still being used for initialization.

Glad to hear that you agree with C++ primer ;-). However, as I found out, the 
default behavior of gcc 3.3.4 is not to call the copy constructor in:
Foo f = 2;
instead it uses direct initialization. I've written a simple test program that 
shows this quite clearly. 

So here the default behavior of gcc contradicts with what I've read in C++ 
primer.

The assigment operator is never called in the statement above, with or without 
-fno-elide-constructors.

See the attached code for an example.

best,
Jeroen
-- 
Kile -- KDE Integrated LaTeX Environment
http://kile.sourceforge.net

Attachment: CopyCtor.tar.gz
Description: application/tgz


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