Problems with KSharedConfig

David Faure faure at kde.org
Fri Feb 23 20:17:06 GMT 2007


On Friday 23 February 2007, Christian Ehrlicher wrote:
> Hi,
> 
> There is a report on kde-windows that kdelibs is currently not 
> compilable with msvc 7.1. After some investigation I found out why it 
> works with msvc 2005, but I don't know exactly how the compiler comes to 
> this conclusion.
> 
> The problem:
> class KSharedConfig has no copy ctor, but is derived from KConfig with a 
> private copy ctor.
> 
> now there is a template KSharedPtr<T>::detach() which applies to 
> KSharedPtr<KSharedConfig>:
> 
> template <class T>
> Q_INLINE_TEMPLATE void KSharedPtr<T>::detach()
> {
>      if (d && d->ref>1) {
>          attach(new T(*d));
>      }
> }
> --> (d == KSharedConfig*, so I'm writing '&KSharedConfig')
> 
> template <KSharedConfig>
> Q_INLINE_TEMPLATE void KSharedPtr<KSharedConfig>::detach()
> {
>      if (&KSharedConfig && (&KSharedConfig)->ref>1) {
>          attach(new KSharedConfig(KSharedConfig));
>      }
> }
> 
> which does not work because KConfig has a private copy ctor (at least 
> this is what msvc7.1 tells us).
> 
> But when I look into the preprocessed source from msvc2005, I see that
> "attach(new T(*d));" is completly optimized away ... !?
> I'm now looking what gcc 3.4.x is doing :)

gcc doesn't instanciate all template methods, only those being called.
msvc7.1 instanciates all template methods, which leads to problems like the above.

Personally, I wonder if detach() is used anywhere. I think it was added
as a "bonus feature", but I'm not sure anything needs it. I just tried compiling
kdelibs without it and (apart from the unit test), nothing used detach.
I'll keep compiling the rest of KDE, but if nothing uses it I suggest we just get rid
of it - copyability shouldn't be a requirement for using KSharedPtr.

-- 
David Faure, faure at kde.org, sponsored by Trolltech to work on KDE,
Konqueror (http://www.konqueror.org), and KOffice (http://www.koffice.org).




More information about the kde-core-devel mailing list