diff --git a/src/corelib/global/qcompilerdetection.h b/src/corelib/global/qcompilerdetection.h index 322f2f4ae28..0c02891e7db 100644 --- a/src/corelib/global/qcompilerdetection.h +++ b/src/corelib/global/qcompilerdetection.h @@ -1121,6 +1121,20 @@ QT_WARNING_POP #endif +// 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 + +// This macro can be used to calculate member offsets for types with a non standard layout. +// It uses the fact that offsetof() is allowed to support those types since C++17 as an optional +// feature. All our compilers do support this, but some issue a warning, so we wrap the offsetof() +// call in a macro that disables the compiler warning. +#define Q_OFFSETOF(Class, member) \ + []() -> size_t { \ + QT_WARNING_PUSH QT_WARNING_DISABLE_INVALID_OFFSETOF \ + return offsetof(Class, member); \ + QT_WARNING_POP \ + }() + /* Proper for-scoping in MIPSpro CC */ diff --git a/src/corelib/global/qglobal.h b/src/corelib/global/qglobal.h index 4329f9f0934..3815f75de50 100644 --- a/src/corelib/global/qglobal.h +++ b/src/corelib/global/qglobal.h @@ -250,22 +250,8 @@ constexpr std::underlying_type_t qToUnderlying(Enum e) noexcept return static_cast>(e); } -// 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 QT_MODULE(x) -// This macro can be used to calculate member offsets for types with a non standard layout. -// It uses the fact that offsetof() is allowed to support those types since C++17 as an optional -// feature. All our compilers do support this, but some issue a warning, so we wrap the offsetof() -// call in a macro that disables the compiler warning. -#define Q_OFFSETOF(Class, member) \ - []() -> size_t { \ - QT_WARNING_PUSH QT_WARNING_DISABLE_INVALID_OFFSETOF \ - return offsetof(Class, member); \ - QT_WARNING_POP \ - }() - QT_END_NAMESPACE // We need to keep QTypeInfo, QSysInfo, QFlags, qDebug & family in qglobal.h for compatibility with Qt 4.