From f46bc118ccd19dbf40685db479efd3ab9fc84342 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Thu, 26 Jan 2023 14:43:05 +0100 Subject: [PATCH] QPermission: add alignment checks for future BC changes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ensure that the classes using ShortData have the same size (already done) and alignment (this patch) as classes that just have a d-pointer. Change-Id: If30352a0bc4beb4b505d6e0eab5077c9c16456ba Reviewed-by: Qt CI Bot Reviewed-by: Tor Arne Vestbø Reviewed-by: Giuseppe D'Angelo (cherry picked from commit 2d254afead50ab0d323f562ac820f876474f3961) Reviewed-by: Qt Cherry-pick Bot --- src/corelib/kernel/qpermissions.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/corelib/kernel/qpermissions.cpp b/src/corelib/kernel/qpermissions.cpp index f8215fbe50d..becc1dc7346 100644 --- a/src/corelib/kernel/qpermissions.cpp +++ b/src/corelib/kernel/qpermissions.cpp @@ -277,11 +277,18 @@ const void *QPermission::data(QMetaType requestedType) const return m_data.data(); } +// check alignof(AlignmentCheck) instead of alignof(void*), in case +// pointers have different alignment inside structs: +struct AlignmentCheck { void *p; }; + #define QT_PERMISSION_IMPL_COMMON(ClassName) \ /* Class##Private is unused until we need it: */ \ static_assert(sizeof(ClassName) == sizeof(void*), \ "You have added too many members to " #ClassName "::ShortData. " \ "Decrease their size or switch to using a d-pointer."); \ + static_assert(alignof(ClassName) == alignof(AlignmentCheck), \ + "You have added members to " #ClassName "::ShortData that are overaligned. " \ + "Decrease their alignment or switch to using a d-pointer."); \ ClassName::ClassName(const ClassName &other) noexcept = default; \ ClassName::~ClassName() = default; \ ClassName &ClassName::operator=(const ClassName &other) noexcept = default; \