From 2ab139596d058cf9cc93e723c340467c70d93b10 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Thu, 10 Jan 2019 13:07:30 +0100 Subject: Fix alignment-warnings about Q_DECLARE_PRIVATE's casts Q_DECLARE_PRIVATE gets used in the declaration of the public class, where the private class is typically visible only as a forward-decl, with no knowledge of what it's based on; consequently, the macro is obliged to use reinterpret_cast<>, which is subject to warnings when the compiler *can* see both types and their alignments differ. The same applies to Q_DECLARE_PRIVATE_D. So suppress gcc's -Wcast-align around the d_func() return statements. (If we get similar problems with other compilers we can add their suppressions likewise; but, for now, we've only seen this on MIPS64, where we use gcc.) This tripped over one use of Q_DECLARE_PRIVATE in a private Q_SLOTS: section; for some reason, gcc didn't like the semicolon on the friend declaration. Changing the context to plain private fixed that. Fixes: QTBUG-72885 Change-Id: I5edc11d46bd4eb820713adede79d53191a7e2736 Reviewed-by: Liang Qi Reviewed-by: Ville Voutilainen Reviewed-by: Boxiang Sun --- src/corelib/global/qglobal.h | 14 ++++++++++---- src/network/access/qnetworkreplyfileimpl_p.h | 1 + 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/corelib/global/qglobal.h b/src/corelib/global/qglobal.h index b608489576..ccab228804 100644 --- a/src/corelib/global/qglobal.h +++ b/src/corelib/global/qglobal.h @@ -1037,14 +1037,20 @@ for (auto _container_ = QtPrivate::qMakeForeachContainer(container); \ template inline T *qGetPtrHelper(T *ptr) { return ptr; } template inline auto qGetPtrHelper(const 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 #define Q_DECLARE_PRIVATE(Class) \ - inline Class##Private* d_func() { return reinterpret_cast(qGetPtrHelper(d_ptr)); } \ - inline const Class##Private* d_func() const { return reinterpret_cast(qGetPtrHelper(d_ptr)); } \ + inline Class##Private* d_func() \ + { Q_CAST_IGNORE_ALIGN(return reinterpret_cast(qGetPtrHelper(d_ptr));) } \ + inline const Class##Private* d_func() const \ + { Q_CAST_IGNORE_ALIGN(return reinterpret_cast(qGetPtrHelper(d_ptr));) } \ friend class Class##Private; #define Q_DECLARE_PRIVATE_D(Dptr, Class) \ - inline Class##Private* d_func() { return reinterpret_cast(qGetPtrHelper(Dptr)); } \ - inline const Class##Private* d_func() const { return reinterpret_cast(qGetPtrHelper(Dptr)); } \ + inline Class##Private* d_func() \ + { Q_CAST_IGNORE_ALIGN(return reinterpret_cast(qGetPtrHelper(Dptr));) } \ + inline const Class##Private* d_func() const \ + { Q_CAST_IGNORE_ALIGN(return reinterpret_cast(qGetPtrHelper(Dptr));) } \ friend class Class##Private; #define Q_DECLARE_PUBLIC(Class) \ diff --git a/src/network/access/qnetworkreplyfileimpl_p.h b/src/network/access/qnetworkreplyfileimpl_p.h index 55aece0bed..48d82abd3f 100644 --- a/src/network/access/qnetworkreplyfileimpl_p.h +++ b/src/network/access/qnetworkreplyfileimpl_p.h @@ -80,6 +80,7 @@ public: private Q_SLOTS: void fileOpenFinished(bool isOpen); +private: Q_DECLARE_PRIVATE(QNetworkReplyFileImpl) }; -- cgit v1.2.3