From 0d9f4e7526fbf1e072aa3518e4e5313332ee4f18 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Mon, 31 Jan 2022 11:10:26 +0100 Subject: [PATCH] Make one QT_REMOVED_SINCE/QT_BUILD_REMOVED_API per module A single global QT_REMOVED_SINCE will start hurting us once more modules downstream of QtCore start using the mechanism. With every use of feature, the set of code that needs to compile under QT_BUILD_REMOVED_API increases. Since we use QT_REMOVED_SINCE in situations where overloading the new and the old function don't work in general, this means all code included by any removed_api.cpp needs to be very carefully written to ensure that any calls to the overload set formed by the combination of old and new function(s) don't create ambiguities. Likewise, the set of APIs that change semantics under QT_BUILD_REMOVED_API also increases. At some point, the combination of removed_api.cpp including almost every module header and almost every header exposing source-incompatibilities when included in removed_api.cpp will make maintenance a headache. By making QT_REMOVED_SINCE and QT_BUILD_REMOVED_API per-module (QT_CORE_REMOVED_SINCE, ...), easy now that we generate the export macros using CMake, we limit the scope of this problem to the module using the feature. Downstream modules (say, QtWidgets) will now see the QtCore API like every other user, even in the widgets/compat/removed_api.cpp TU. Pick-to: 6.3 Change-Id: I177bc7bd5aa8791639f97946c98e4592d2c7f9d9 Reviewed-by: Edward Welbourne Reviewed-by: Qt CI Bot Reviewed-by: Fabian Kosmale --- cmake/modulecppexports.h.in | 6 ++++ src/corelib/compat/removed_api.cpp | 14 ++++---- src/corelib/global/qglobal.h | 36 -------------------- src/corelib/global/qoperatingsystemversion.h | 2 +- src/corelib/kernel/qmetatype.h | 2 +- src/corelib/plugin/quuid.h | 4 +-- src/corelib/text/qbytearraylist.h | 2 +- src/corelib/text/qbytearraymatcher.h | 4 +-- src/corelib/time/qcalendar.h | 2 +- src/corelib/tools/qcryptographichash.h | 4 +-- src/corelib/tools/qversionnumber.h | 3 +- src/widgets/compat/removed_api.cpp | 8 ++--- src/widgets/widgets/qmenu.h | 2 +- src/widgets/widgets/qmenubar.h | 2 +- src/widgets/widgets/qtoolbar.h | 2 +- 15 files changed, 32 insertions(+), 61 deletions(-) diff --git a/cmake/modulecppexports.h.in b/cmake/modulecppexports.h.in index 68b0353a97b..ace3cd90e0c 100644 --- a/cmake/modulecppexports.h.in +++ b/cmake/modulecppexports.h.in @@ -52,4 +52,10 @@ # define Q_@module_define_infix@_EXPORT #endif +#ifdef QT_@module_define_infix@_BUILD_REMOVED_API +#define QT_@module_define_infix@_REMOVED_SINCE(major, minor) QT_DEPRECATED_SINCE(major, minor) +#else +#define QT_@module_define_infix@_REMOVED_SINCE(major, minor) 0 +#endif + #endif // @header_base_name_upper@_H diff --git a/src/corelib/compat/removed_api.cpp b/src/corelib/compat/removed_api.cpp index d21813bbacf..fda9a3fe72f 100644 --- a/src/corelib/compat/removed_api.cpp +++ b/src/corelib/compat/removed_api.cpp @@ -37,13 +37,13 @@ ** ****************************************************************************/ -#define QT_BUILD_REMOVED_API +#define QT_CORE_BUILD_REMOVED_API #include "qglobal.h" QT_USE_NAMESPACE -#if QT_REMOVED_SINCE(6, 1) +#if QT_CORE_REMOVED_SINCE(6, 1) #include "qmetatype.h" @@ -58,9 +58,9 @@ int QMetaType::id() const return 0; } -#endif // QT_REMOVED_SINCE(6, 1) +#endif // QT_CORE_REMOVED_SINCE(6, 1) -#if QT_REMOVED_SINCE(6, 3) +#if QT_CORE_REMOVED_SINCE(6, 3) #include "qbytearraymatcher.h" @@ -141,9 +141,9 @@ int QOperatingSystemVersion::compare(const QOperatingSystemVersion &v1, return QOperatingSystemVersionBase::compare(v1, v2); } -#endif // QT_REMOVED_SINCE(6, 3) +#endif // QT_CORE_REMOVED_SINCE(6, 3) -#if QT_REMOVED_SINCE(6, 4) +#if QT_CORE_REMOVED_SINCE(6, 4) #include "qcalendar.h" @@ -178,4 +178,4 @@ QT_WARNING_POP // #include // // implement removed functions from qotherheader.h -#endif // QT_REMOVED_SINCE(6, 4) +#endif // QT_CORE_REMOVED_SINCE(6, 4) diff --git a/src/corelib/global/qglobal.h b/src/corelib/global/qglobal.h index ad771d4f5fa..864e3b1d87f 100644 --- a/src/corelib/global/qglobal.h +++ b/src/corelib/global/qglobal.h @@ -447,42 +447,6 @@ typedef double qreal; #define QT_DEPRECATED_VERSION_5(minor) QT_DEPRECATED_VERSION_5_##minor #define QT_DEPRECATED_VERSION(major, minor) QT_DEPRECATED_VERSION_##major##_##minor -/* - QT_REMOVED_SINCE(major, minor) evaluates as true if the Qt version is greater than - the deprecation point specified \e and QT_BUILD_REMOVED_API is defined. - - Use it to remove functions from the API, but not the ABI, by moving their definitions - into the module's \c{removed_api/} subdir and defining QT_BUILD_REMOVED_API. - - Example: - - // header - #if QT_REMOVED_SINCE(6, 3) - void removedFunction(); // function removed since Qt 6.3 - #endif - - // implementation - // ... moved from here ... - - // removed_api/some.cpp - #define QT_BUILD_REMOVED_API - #include - - #include - - #if QT_REMOVED_SINCE(6, 3) - void removedFunction() { newFunction(); } - #endif - - The function is now removed from the API, but remains in the ABI until - the deprecation point moves past 6.3. -*/ -#ifdef QT_BUILD_REMOVED_API -#define QT_REMOVED_SINCE(major, minor) QT_DEPRECATED_SINCE(major, minor) -#else -#define QT_REMOVED_SINCE(major, minor) 0 -#endif - #ifdef __cplusplus // A tag to help mark stuff deprecated (cf. QStringViewLiteral) namespace QtPrivate { diff --git a/src/corelib/global/qoperatingsystemversion.h b/src/corelib/global/qoperatingsystemversion.h index 92e2848e2c5..31bfadb9e0c 100644 --- a/src/corelib/global/qoperatingsystemversion.h +++ b/src/corelib/global/qoperatingsystemversion.h @@ -265,7 +265,7 @@ public: private: QOperatingSystemVersion() = default; -#if QT_REMOVED_SINCE(6, 3) +#if QT_CORE_REMOVED_SINCE(6, 3) // ### Qt 7: Remove. It's only here for backwards compat with previous inline calls. [[maybe_unused]] static int compare(const QOperatingSystemVersion &v1, const QOperatingSystemVersion &v2); diff --git a/src/corelib/kernel/qmetatype.h b/src/corelib/kernel/qmetatype.h index 62798f4cc81..36de60c1b17 100644 --- a/src/corelib/kernel/qmetatype.h +++ b/src/corelib/kernel/qmetatype.h @@ -445,7 +445,7 @@ public: bool isValid() const; bool isRegistered() const; -#if QT_REMOVED_SINCE(6, 1) || defined(Q_QDOC) +#if QT_CORE_REMOVED_SINCE(6, 1) || defined(Q_QDOC) int id() const; #else // ### Qt 7: Remove traces of out of line version diff --git a/src/corelib/plugin/quuid.h b/src/corelib/plugin/quuid.h index 9229d5b694d..cac6913d6bf 100644 --- a/src/corelib/plugin/quuid.h +++ b/src/corelib/plugin/quuid.h @@ -100,7 +100,7 @@ public: explicit QUuid(QAnyStringView string) noexcept : QUuid{fromString(string)} {} static QUuid fromString(QAnyStringView string) noexcept; -#if QT_REMOVED_SINCE(6, 3) +#if QT_CORE_REMOVED_SINCE(6, 3) explicit QUuid(const QString &); static QUuid fromString(QStringView string) noexcept; static QUuid fromString(QLatin1String string) noexcept; @@ -110,7 +110,7 @@ public: QString toString(StringFormat mode = WithBraces) const; QByteArray toByteArray(StringFormat mode = WithBraces) const; QByteArray toRfc4122() const; -#if QT_REMOVED_SINCE(6, 3) +#if QT_CORE_REMOVED_SINCE(6, 3) static QUuid fromRfc4122(const QByteArray &); #endif static QUuid fromRfc4122(QByteArrayView) noexcept; diff --git a/src/corelib/text/qbytearraylist.h b/src/corelib/text/qbytearraylist.h index de5546c8ce6..aaf3b4b1169 100644 --- a/src/corelib/text/qbytearraylist.h +++ b/src/corelib/text/qbytearraylist.h @@ -58,7 +58,7 @@ typedef QMutableListIterator QMutableByteArrayListIterator; #ifndef Q_CLANG_QDOC namespace QtPrivate { -#if QT_REMOVED_SINCE(6, 3) && QT_POINTER_SIZE != 4 +#if QT_CORE_REMOVED_SINCE(6, 3) && QT_POINTER_SIZE != 4 QByteArray Q_CORE_EXPORT QByteArrayList_join(const QByteArrayList *that, const char *separator, int separatorLength); #endif QByteArray Q_CORE_EXPORT QByteArrayList_join(const QByteArrayList *that, const char *sep, qsizetype len); diff --git a/src/corelib/text/qbytearraymatcher.h b/src/corelib/text/qbytearraymatcher.h index 4aac69f30af..581b3c34a5d 100644 --- a/src/corelib/text/qbytearraymatcher.h +++ b/src/corelib/text/qbytearraymatcher.h @@ -65,7 +65,7 @@ public: void setPattern(const QByteArray &pattern); -#if QT_REMOVED_SINCE(6, 3) +#if QT_CORE_REMOVED_SINCE(6, 3) qsizetype indexIn(const QByteArray &ba, qsizetype from = 0) const; #else Q_WEAK_OVERLOAD @@ -107,7 +107,7 @@ protected: // compiler-generated copy/more ctors/assignment operators are ok! ~QStaticByteArrayMatcherBase() = default; -#if QT_REMOVED_SINCE(6, 3) && QT_POINTER_SIZE != 4 +#if QT_CORE_REMOVED_SINCE(6, 3) && QT_POINTER_SIZE != 4 Q_CORE_EXPORT int indexOfIn(const char *needle, uint nlen, const char *haystack, int hlen, int from) const noexcept; #endif Q_CORE_EXPORT qsizetype indexOfIn(const char *needle, size_t nlen, diff --git a/src/corelib/time/qcalendar.h b/src/corelib/time/qcalendar.h index adfbc66ffb3..853b45b2a94 100644 --- a/src/corelib/time/qcalendar.h +++ b/src/corelib/time/qcalendar.h @@ -146,7 +146,7 @@ public: explicit QCalendar(); // Gregorian, optimised explicit QCalendar(System system); -#if QT_REMOVED_SINCE(6, 4) +#if QT_CORE_REMOVED_SINCE(6, 4) explicit QCalendar(QLatin1String name); explicit QCalendar(QStringView name); #endif diff --git a/src/corelib/tools/qcryptographichash.h b/src/corelib/tools/qcryptographichash.h index 83aed7c64c9..3f586055b14 100644 --- a/src/corelib/tools/qcryptographichash.h +++ b/src/corelib/tools/qcryptographichash.h @@ -108,7 +108,7 @@ public: QT_DEPRECATED_VERSION_X_6_4("Use the QByteArrayView overload instead") void addData(const char *data, qsizetype length); #endif -#if QT_REMOVED_SINCE(6, 3) +#if QT_CORE_REMOVED_SINCE(6, 3) void addData(const QByteArray &data); #endif void addData(QByteArrayView data) noexcept; @@ -117,7 +117,7 @@ public: QByteArray result() const; QByteArrayView resultView() const noexcept; -#if QT_REMOVED_SINCE(6, 3) +#if QT_CORE_REMOVED_SINCE(6, 3) static QByteArray hash(const QByteArray &data, Algorithm method); #endif static QByteArray hash(QByteArrayView data, Algorithm method); diff --git a/src/corelib/tools/qversionnumber.h b/src/corelib/tools/qversionnumber.h index 3bdfdcd7f82..559a09d7503 100644 --- a/src/corelib/tools/qversionnumber.h +++ b/src/corelib/tools/qversionnumber.h @@ -304,7 +304,8 @@ public: } #endif -#if QT_REMOVED_SINCE(6, 4) + +#if QT_CORE_REMOVED_SINCE(6, 4) [[nodiscard]] Q_CORE_EXPORT static QVersionNumber fromString(const QString &string, int *suffixIndex); [[nodiscard]] Q_CORE_EXPORT static QVersionNumber fromString(QLatin1String string, int *suffixIndex); [[nodiscard]] Q_CORE_EXPORT static QVersionNumber fromString(QStringView string, int *suffixIndex); diff --git a/src/widgets/compat/removed_api.cpp b/src/widgets/compat/removed_api.cpp index 32f4e7c8069..173cd5c4bf7 100644 --- a/src/widgets/compat/removed_api.cpp +++ b/src/widgets/compat/removed_api.cpp @@ -37,13 +37,13 @@ ** ****************************************************************************/ -#define QT_BUILD_REMOVED_API +#define QT_WIDGETS_BUILD_REMOVED_API -#include "qglobal.h" +#include "qtwidgetsglobal.h" QT_USE_NAMESPACE -#if QT_REMOVED_SINCE(6, 3) +#if QT_WIDGETS_REMOVED_SINCE(6, 3) #include "qmenu.h" @@ -111,4 +111,4 @@ QAction *QMenuBar::addAction(const QString &text, const QObject *receiver, const // #include // // implement removed functions from qotherheader.h -#endif // QT_REMOVED_SINCE(6, 3) +#endif // QT_WIDGETS_REMOVED_SINCE(6, 3) diff --git a/src/widgets/widgets/qmenu.h b/src/widgets/widgets/qmenu.h index 1b14263e6bf..ef5bdf7236d 100644 --- a/src/widgets/widgets/qmenu.h +++ b/src/widgets/widgets/qmenu.h @@ -76,7 +76,7 @@ public: ~QMenu(); using QWidget::addAction; -#if QT_REMOVED_SINCE(6, 3) +#if QT_WIDGETS_REMOVED_SINCE(6, 3) QAction *addAction(const QString &text); QAction *addAction(const QIcon &icon, const QString &text); #if !QT_CONFIG(shortcut) diff --git a/src/widgets/widgets/qmenubar.h b/src/widgets/widgets/qmenubar.h index 43bcd39f71d..9763954f829 100644 --- a/src/widgets/widgets/qmenubar.h +++ b/src/widgets/widgets/qmenubar.h @@ -64,7 +64,7 @@ public: ~QMenuBar(); using QWidget::addAction; -#if QT_REMOVED_SINCE(6, 3) +#if QT_WIDGETS_REMOVED_SINCE(6, 3) QAction *addAction(const QString &text); QAction *addAction(const QString &text, const QObject *receiver, const char* member); #endif diff --git a/src/widgets/widgets/qtoolbar.h b/src/widgets/widgets/qtoolbar.h index 09f639d3e7b..66c191831da 100644 --- a/src/widgets/widgets/qtoolbar.h +++ b/src/widgets/widgets/qtoolbar.h @@ -90,7 +90,7 @@ public: void clear(); using QWidget::addAction; -#if QT_REMOVED_SINCE(6, 3) +#if QT_WIDGETS_REMOVED_SINCE(6, 3) QAction *addAction(const QString &text); QAction *addAction(const QIcon &icon, const QString &text); QAction *addAction(const QString &text, const QObject *receiver, const char* member);