Pimpl copying

André Wöbbeking Woebbeking at onlinehome.de
Fri Jul 14 09:33:55 BST 2006

On Thursday 13 July 2006 23:05, Peter Kümmel wrote:
> While debugging KTempDirTest on windows I've found that this patch
> Index: ktempdirtest.cpp
> ===================================================================
> --- ktempdirtest.cpp    (revision 561767)
> +++ ktempdirtest.cpp    (working copy)
> @@ -26,7 +26,7 @@
>  void KTempDirTest::testBasic()
>  {
> -       KTempDir dir = KTempDir("test");

normal ctor and then copy ctor

> +       KTempDir dir("test");

normal ctor

> avoids a crash caused by dereferencing a uninitialized variable.
> (wonder why it works with gcc)

This test should also lead to double deletion when dir is destroyed.

> I fear kdelibs is full of this bug and think we should catch
> such constructs at compile time.

Many classes with pimpls are subclasses of QObject which can't be 
copied/assigned. Some other classes use QSharedDataPointer. In both 
cases you don't have that problem.

> Shouldn't we introduce a coding policy something like this:

I think people should be aware of this pitfall (could anyone add this to 

> This introduces a new macro KDE_PIMPL_COPYABLE
> which declares the pimpl AND the copy functions.
> KDE_PIMPL_UNCOPYABLE declares the copy functions
> as private, so we get an error at compile time.
> Or is there already a Qt way to handle this?



More information about the kde-core-devel mailing list