From f2bd46d1df587a3d9eac485c5e98caa98b12909d Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Thu, 13 Jun 2019 23:25:18 +0200 Subject: 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 --- src/corelib/global/qglobal.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/corelib/global/qglobal.h') 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 inline T *qGetPtrHelper(T *ptr) { return ptr; } -template inline auto qGetPtrHelper(const Ptr &ptr) -> decltype(ptr.operator->()) { return ptr.operator->(); } +template 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 -- cgit v1.2.3