summaryrefslogtreecommitdiffstats
path: root/src/corelib/global/qglobal.h
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2019-06-13 23:25:18 +0200
committerMarc Mutz <marc.mutz@kdab.com>2019-06-15 18:40:24 +0200
commitf2bd46d1df587a3d9eac485c5e98caa98b12909d (patch)
tree0fd7a6d3614d0c6e783469dffa6e44d8a9f1a1f8 /src/corelib/global/qglobal.h
parent079dafc42fdfddbc6bff7d343463e16151afeb2d (diff)
Fix deep-const-correctness of qGetPtrHelper() for smart pointers
The function qGetPtrHelper() is mainly used to implement d_func() within the Q_DECLARE_PRIVATE() macro. The whole purpose of d_func() is to propagate const deeply. But if a smart pointer implements this by itself, then the old version of qGetPtrHelper(), by taking the Ptr as a const-&, would always return a const payload pointer, which would fail in the following reinterpret_cast in d_func() to mutable payloads. This was found while experimenting with making QExplicitlySharedDataPointer deep const-correct, and I have no explanation why it seems to have worked with QSharedDataPointer, which is deep-const-correct already. Change-Id: Iee2e8fcce89c58ba2af7818de6f79ed39c5a4030 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/global/qglobal.h')
-rw-r--r--src/corelib/global/qglobal.h2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/corelib/global/qglobal.h b/src/corelib/global/qglobal.h
index 87ae704ca4..15f4621cc0 100644
--- a/src/corelib/global/qglobal.h
+++ b/src/corelib/global/qglobal.h
@@ -1096,7 +1096,7 @@ for (auto _container_ = QtPrivate::qMakeForeachContainer(container); \
#endif
template <typename T> inline T *qGetPtrHelper(T *ptr) { return ptr; }
-template <typename Ptr> inline auto qGetPtrHelper(const Ptr &ptr) -> decltype(ptr.operator->()) { return ptr.operator->(); }
+template <typename Ptr> inline auto qGetPtrHelper(Ptr &ptr) -> decltype(ptr.operator->()) { return ptr.operator->(); }
// The body must be a statement:
#define Q_CAST_IGNORE_ALIGN(body) QT_WARNING_PUSH QT_WARNING_DISABLE_GCC("-Wcast-align") body QT_WARNING_POP