Pimpl copying
Clarence Dang
dang at kde.org
Fri Jul 14 13:07:16 BST 2006
On Friday 14 July 2006 19:55, Reinhold Kainhofer wrote:
> Am Freitag, 14. Juli 2006 11:28 schrieb Lubos Lunak:
> > On Friday 14 July 2006 10:33, André Wöbbeking wrote:
> > > On Thursday 13 July 2006 23:05, Peter Kümmel wrote:
> > > > void KTempDirTest::testBasic()
> > > > {
> > > > - KTempDir dir = KTempDir("test");
> > >
> > > normal ctor and then copy ctor
> >
> > No. It's just syntactic sugar functionally completely equivalent to the
> > case below with just normal ctor. If any compiler uses copy ctor here
> > it's broken.
>
> Stroustrup's book says that
> KTempDir dir = KTempDir("test");
> and
> KTempDir dir("test");
> are equivalent. I.e. the first one should not use ctor and then copy. I had
> a similar discussion with Mark a while ago (we were discussion which one
> was more efficient. Turned out they should be the same)
The bit from the gcc manpage that Lubos referred to:
~~~~
-fno-elide-constructors
The C++ standard allows an implementation to omit creating a temporary
which is only used to initialize another object of the same type. Specify-
ing this option disables that optimization, and forces G++ to call the copy
constructor in all cases.
~~~~
Maybe Stroustrup doesn't know his own language :)
More information about the kde-core-devel
mailing list