summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qshareddata.h
diff options
context:
space:
mode:
authorKevin Funk <kfunk@kde.org>2014-06-27 13:49:55 +0200
committerKevin Funk <kevin.funk@kdab.com>2014-07-09 00:23:53 +0200
commite112c2ee20f89f288a4f0a13827f0b64067096f0 (patch)
tree1e7612d5993a96d68c254826863113c690b0df40 /src/corelib/tools/qshareddata.h
parent01cc6254068b96a155ac9376458dd4580c7c7b0b (diff)
Make QExplicitlySharedDataPointer<T> copy-ctor from QESDP<X> more safe
With "QExplicitlySharedDataPointer::QExplicitlySharedDataPointer( const QExplicitlySharedDataPointer<X> & other)" implicitly doing an static_cast<T *>(...) on other.data(), this could lead to dangerous use of this copy constructor. Example code: QExplicitlySharedDataPointer<Base> base(new Base); QExplicitlySharedDataPointer<Derived> derived(base); // that works! This patchs disables the use of the static_cast, and adds a new define called QT_ENABLE_QEXPLICITLYSHAREDDATAPOINTER_STATICCAST to re-enable that code path. Note, that the other way-around (assigning 'derived' to 'base') still works as intended. Other side note: QtXmlPatterns is relying heavily on the hidden static_cast "feature". The other default Qt modules compile fine with the static_cast removed. [ChangeLog][Important Behavior Changes] QExplicitelySharedDataPointer's copy constructor which performs a static_cast from "X *" to "T *" (when constructing a QExplicitlySharedDataPointer<T> from a QExplicitlySharedDataPointer<X>) doesn't perform a static_cast from "X *" to "T *" any more. Instead, an implicit cast is now performed. This change will break compilation of code that relied on the downcast (i.e. cast towards a more derived type) of the templated type when copy costructing a QExplicitelySharedDataPointer object. Please refer to the class documentation for more information about this issue and a workaround to keep old code compiling. Change-Id: Id32aba6cda4e6d44728d7bc3a5c0c7a20f19adc6 Reviewed-by: Kevin Funk <kevin.funk@kdab.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/tools/qshareddata.h')
-rw-r--r--src/corelib/tools/qshareddata.h7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/corelib/tools/qshareddata.h b/src/corelib/tools/qshareddata.h
index 415ea0d6c7..d85184e995 100644
--- a/src/corelib/tools/qshareddata.h
+++ b/src/corelib/tools/qshareddata.h
@@ -167,7 +167,12 @@ public:
inline QExplicitlySharedDataPointer(const QExplicitlySharedDataPointer<T> &o) : d(o.d) { if (d) d->ref.ref(); }
template<class X>
- inline QExplicitlySharedDataPointer(const QExplicitlySharedDataPointer<X> &o) : d(static_cast<T *>(o.data()))
+ inline QExplicitlySharedDataPointer(const QExplicitlySharedDataPointer<X> &o)
+#ifdef QT_ENABLE_QEXPLICITLYSHAREDDATAPOINTER_STATICCAST
+ : d(static_cast<T *>(o.data()))
+#else
+ : d(o.data())
+#endif
{
if(d)
d->ref.ref();