From d1213157df98819fa29b1da95f712546c5b9dbab Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Wed, 12 Jun 2024 09:52:27 +0200 Subject: [PATCH] QLoggingCategory: Deprecate non-static, non-forward-declared categories Qt-internal logging categories should either be static or declared in a header and therefore shared between multiple translation units. This way we minimize the number of exposed symbols. We want to minimize the number of exposed symbols in order to reduce the chance of name clashes. In the same vein, when exporting a Qt-internal logging category it should be declared explicitly as Qt-internal. The code importing it may not be a Qt library after all. Task-number: QTBUG-67692 Change-Id: If1c045471fe52226a34cc94a5fe9b0c9a2de56b5 Reviewed-by: Thiago Macieira --- src/corelib/io/qloggingcategory.h | 8 +++++++- src/corelib/io/qloggingregistry_p.h | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/corelib/io/qloggingcategory.h b/src/corelib/io/qloggingcategory.h index 1b2731fa1e0..13b6cc17b8d 100644 --- a/src/corelib/io/qloggingcategory.h +++ b/src/corelib/io/qloggingcategory.h @@ -113,7 +113,10 @@ template <> const bool QLoggingCategoryMacroHolder::IsOutputEnable using QtPrivateLogging::name; #define Q_DECLARE_EXPORTED_LOGGING_CATEGORY(name, export_macro) \ - namespace QtPrivateLogging { export_macro const QLoggingCategory &name(); } \ + namespace QtPrivateLogging { \ + Q_DECL_DEPRECATED_X("Use QT_DECLARE_EXPORTED_QT_LOGGING_CATEGORY in Qt") \ + export_macro const QLoggingCategory &name(); \ + } \ using QtPrivateLogging::name; #define Q_LOGGING_CATEGORY_IMPL(name, ...) \ @@ -134,6 +137,9 @@ template <> const bool QLoggingCategoryMacroHolder::IsOutputEnable #define Q_LOGGING_CATEGORY(name, ...) \ namespace QtPrivateLogging { Q_LOGGING_CATEGORY_IMPL(name, __VA_ARGS__) } \ Q_WEAK_OVERLOAD \ + Q_DECL_DEPRECATED_X("Use Q_STATIC_LOGGING_CATEGORY or add " \ + "either Q_DECLARE_LOGGING_CATEGORY or " \ + "QT_DECLARE_EXPORTED_QT_LOGGING_CATEGORY in a header") \ const QLoggingCategory &name() { return QtPrivateLogging::name(); } #endif diff --git a/src/corelib/io/qloggingregistry_p.h b/src/corelib/io/qloggingregistry_p.h index 18683294f28..1102e533241 100644 --- a/src/corelib/io/qloggingregistry_p.h +++ b/src/corelib/io/qloggingregistry_p.h @@ -54,6 +54,7 @@ QT_BEGIN_NAMESPACE Q_LOGGING_CATEGORY_WITH_ENV_OVERRIDE_IMPL(name, env, categoryName) \ } \ Q_WEAK_OVERLOAD \ + Q_DECL_DEPRECATED_X("Logging categories should either be static or declared in a header") \ const QLoggingCategory &name() { return QtPrivateLogging::name(); } #endif