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 <liang.qi@qt.io>
Reviewed-by: Ville Voutilainen <ville.voutilainen@qt.io>
Reviewed-by: Boxiang Sun <daetalusun@gmail.com>
This commit is contained in:
Edward Welbourne 2019-01-10 13:07:30 +01:00 committed by Liang Qi
parent c365fa49d8
commit 2ab139596d
2 changed files with 11 additions and 4 deletions

View File

@ -1037,14 +1037,20 @@ for (auto _container_ = QtPrivate::qMakeForeachContainer(container); \
template <typename T> inline T *qGetPtrHelper(T *ptr) { return ptr; } 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(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) \ #define Q_DECLARE_PRIVATE(Class) \
inline Class##Private* d_func() { return reinterpret_cast<Class##Private *>(qGetPtrHelper(d_ptr)); } \ inline Class##Private* d_func() \
inline const Class##Private* d_func() const { return reinterpret_cast<const Class##Private *>(qGetPtrHelper(d_ptr)); } \ { Q_CAST_IGNORE_ALIGN(return reinterpret_cast<Class##Private *>(qGetPtrHelper(d_ptr));) } \
inline const Class##Private* d_func() const \
{ Q_CAST_IGNORE_ALIGN(return reinterpret_cast<const Class##Private *>(qGetPtrHelper(d_ptr));) } \
friend class Class##Private; friend class Class##Private;
#define Q_DECLARE_PRIVATE_D(Dptr, Class) \ #define Q_DECLARE_PRIVATE_D(Dptr, Class) \
inline Class##Private* d_func() { return reinterpret_cast<Class##Private *>(qGetPtrHelper(Dptr)); } \ inline Class##Private* d_func() \
inline const Class##Private* d_func() const { return reinterpret_cast<const Class##Private *>(qGetPtrHelper(Dptr)); } \ { Q_CAST_IGNORE_ALIGN(return reinterpret_cast<Class##Private *>(qGetPtrHelper(Dptr));) } \
inline const Class##Private* d_func() const \
{ Q_CAST_IGNORE_ALIGN(return reinterpret_cast<const Class##Private *>(qGetPtrHelper(Dptr));) } \
friend class Class##Private; friend class Class##Private;
#define Q_DECLARE_PUBLIC(Class) \ #define Q_DECLARE_PUBLIC(Class) \

View File

@ -80,6 +80,7 @@ public:
private Q_SLOTS: private Q_SLOTS:
void fileOpenFinished(bool isOpen); void fileOpenFinished(bool isOpen);
private:
Q_DECLARE_PRIVATE(QNetworkReplyFileImpl) Q_DECLARE_PRIVATE(QNetworkReplyFileImpl)
}; };