diff --git a/src/corelib/global/qtclasshelpermacros.h b/src/corelib/global/qtclasshelpermacros.h index a608b11fb99..5b0a67b4eae 100644 --- a/src/corelib/global/qtclasshelpermacros.h +++ b/src/corelib/global/qtclasshelpermacros.h @@ -83,6 +83,31 @@ QT_BEGIN_NAMESPACE return *this; \ } +/* + This macro defines the RO5 special member functions (destructor, + copy+move constructors and assignment operators) as defaulted. + + Normally we don't use this macro if we're fine with these functions + to be public; we instead leave a comment in the class declaration, + something like: + + // compiler-generated special member functions are fine! + + In some cases a class may need to redeclare these functions, for + instance if it wants to change their accessibility. Since + defaulting all five is boilerplate, use this macro instead. + + Note that the default constructor is not covered, and this macro + will prevented its automatic generation. +*/ + +#define QT_DECLARE_RO5_SMF_AS_DEFAULTED(Class) \ + ~Class() = default; \ + Class(const Class &) = default; \ + Class(Class &&) = default; \ + Class &operator=(const Class &) = default; \ + Class &operator=(Class &&) = default; + /* These macros can be used to define tag structs in the preferred way (ie. with explicit default ctor). diff --git a/src/corelib/global/qxpfunctional.h b/src/corelib/global/qxpfunctional.h index 320ca5417c8..2dd7de669d0 100644 --- a/src/corelib/global/qxpfunctional.h +++ b/src/corelib/global/qxpfunctional.h @@ -72,11 +72,7 @@ template class function_ref_base { protected: - ~function_ref_base() = default; - function_ref_base(const function_ref_base &) = default; - function_ref_base(function_ref_base &&) = default; - function_ref_base &operator=(const function_ref_base &) = default; - function_ref_base &operator=(function_ref_base &&) = default; + QT_DECLARE_RO5_SMF_AS_DEFAULTED(function_ref_base) using BoundEntityType = detail::BoundEntityType; diff --git a/src/corelib/tools/qlist.h b/src/corelib/tools/qlist.h index c9b931e420a..eac3fce608a 100644 --- a/src/corelib/tools/qlist.h +++ b/src/corelib/tools/qlist.h @@ -32,11 +32,7 @@ template struct QListSpecialMethodsBase { protected: QListSpecialMethodsBase() = default; - ~QListSpecialMethodsBase() = default; - QListSpecialMethodsBase(const QListSpecialMethodsBase &) = default; - QListSpecialMethodsBase(QListSpecialMethodsBase &&) = default; - QListSpecialMethodsBase &operator=(const QListSpecialMethodsBase &) = default; - QListSpecialMethodsBase &operator=(QListSpecialMethodsBase &&) = default; + QT_DECLARE_RO5_SMF_AS_DEFAULTED(QListSpecialMethodsBase) using Self = QList; Self *self() { return static_cast(this); } @@ -58,11 +54,7 @@ template struct QListSpecialMethods : QListSpecialMethodsBase { protected: QListSpecialMethods() = default; - ~QListSpecialMethods() = default; - QListSpecialMethods(const QListSpecialMethods &) = default; - QListSpecialMethods(QListSpecialMethods &&) = default; - QListSpecialMethods &operator=(const QListSpecialMethods &) = default; - QListSpecialMethods &operator=(QListSpecialMethods &&) = default; + QT_DECLARE_RO5_SMF_AS_DEFAULTED(QListSpecialMethods) public: using QListSpecialMethodsBase::indexOf;