From f080f161237e3310fca0955742218276069e4868 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 29 Jan 2025 14:45:40 +0100 Subject: [PATCH] QFlags: make base class SMFs protected This is from one of the 90s books on C++ Coding Style: Destructors of (public) base classes should be either public and virtual or else protected and non-virtual. The dtors of the various QFlags helper classes were public and non-virtual, allowing slicing and use outside of QFlags. Fix both following the rule and making the dtors protected. Previously, this would have been enough, but Clang started to warn about undeclared copy- and move-SMFs in the presence of a user-declared dtor, so need to declare all five. Found in API-review. Pick-to: 6.9 Change-Id: I70d1163f7bb42d981bf550418d2775a784bd416e Reviewed-by: Volker Hilsheimer --- src/corelib/global/qflags.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/corelib/global/qflags.h b/src/corelib/global/qflags.h index 05225b98d23..1c1e2ef04d1 100644 --- a/src/corelib/global/qflags.h +++ b/src/corelib/global/qflags.h @@ -71,6 +71,7 @@ protected: Int i = 0; + QT_DECLARE_RO5_SMF_AS_DEFAULTED(QFlagsStorage) public: constexpr inline QFlagsStorage() noexcept = default; constexpr inline explicit QFlagsStorage(std::in_place_t, Int v) : i(v) {} @@ -80,6 +81,8 @@ template )> struct QFlagsStorageHelper : QFlagsStorage { using QFlagsStorage::QFlagsStorage; +protected: + QT_DECLARE_RO5_SMF_AS_DEFAULTED(QFlagsStorageHelper) }; template struct QFlagsStorageHelper : QFlagsStorage { @@ -94,6 +97,8 @@ template struct QFlagsStorageHelper : QFlagsS #ifdef QT_TYPESAFE_FLAGS constexpr inline explicit operator QFlag() const noexcept { return QFlag(this->i); } #endif +protected: + QT_DECLARE_RO5_SMF_AS_DEFAULTED(QFlagsStorageHelper) }; } // namespace QtPrivate