From fb0c7a9956824fbc3e3a3ab70cf7e2e5a622e85d Mon Sep 17 00:00:00 2001 From: Fabian Kosmale Date: Sun, 6 Feb 2022 20:09:54 +0100 Subject: [PATCH] QVariant: reduce transitive includes Forward declare more types in qvariant.h, and do the same for qdebug.h (which will be removed from qvariant in a separate patch). As we now only forward declare containers (e.g. QMap, QList, ...), code which includes , ... breaks without further adjustment: So far, those headers simply included qvariant.h. However, by introducing new actual headers for those types and adjusting sync.profile, we can avoid this issue. To avoid breaking leaf modules and user code, we make the change opt-in: Unless QT_LEAN_HEADERS is defined to a value of >= 1, we still include the superfluous headers. We also set this macro in qtbase via QT_EXTRA_INTERNAL_TARGET_DEFINES. [ChangeLog][Potentially Source-Incompatible Changes] qvariant.h no longer includes , , , , and . Code that relied on transitive includes might need to explicitly include those headers now. Notably, including (or qvariant.h) is no longer sufficient when using QVariant(List|Map|Hash). Using them now requires including respectively , , or . Alternatively, including and the , or header also works. [ChangeLog][Potentially Source-Incompatible Changes] qdebug.h no longer includes , , and . Code that relied on transitive includes might need to explicitly include those headers now. Task-number: QTBUG-97601 Change-Id: I142e5de709ed0b305716369a3266389ab7fbbb71 Reviewed-by: Thiago Macieira Reviewed-by: Marc Mutz --- .cmake.conf | 3 ++ src/corelib/CMakeLists.txt | 1 + src/corelib/io/qdebug.h | 14 ++++--- src/corelib/kernel/qvariant.h | 19 ++++----- src/corelib/kernel/qvarianthash.h | 56 +++++++++++++++++++++++++ src/corelib/kernel/qvariantlist.h | 55 ++++++++++++++++++++++++ src/corelib/kernel/qvariantmap.h | 56 +++++++++++++++++++++++++ src/corelib/tools/qsharedpointer_impl.h | 6 ++- sync.profile | 1 - 9 files changed, 193 insertions(+), 18 deletions(-) create mode 100644 src/corelib/kernel/qvarianthash.h create mode 100644 src/corelib/kernel/qvariantlist.h create mode 100644 src/corelib/kernel/qvariantmap.h diff --git a/.cmake.conf b/.cmake.conf index 57401cb9b9b..ee63c78947d 100644 --- a/.cmake.conf +++ b/.cmake.conf @@ -22,3 +22,6 @@ set(QT_SUPPORTED_MIN_CMAKE_VERSION_FOR_USING_QT_STATIC "3.21") # in sync. set(QT_MIN_NEW_POLICY_CMAKE_VERSION "3.16") set(QT_MAX_NEW_POLICY_CMAKE_VERSION "3.21") + +# set (git) module specific defines +set(QT_EXTRA_INTERNAL_TARGET_DEFINES "QT_LEAN_HEADERS=1") diff --git a/src/corelib/CMakeLists.txt b/src/corelib/CMakeLists.txt index 1cf6a9c4868..6f5e0ec6cf7 100644 --- a/src/corelib/CMakeLists.txt +++ b/src/corelib/CMakeLists.txt @@ -145,6 +145,7 @@ qt_internal_add_module(Core kernel/qtimer.cpp kernel/qtimer.h kernel/qtranslator.cpp kernel/qtranslator.h kernel/qtranslator_p.h kernel/qvariant.cpp kernel/qvariant.h kernel/qvariant_p.h + kernel/qvariantmap.h kernel/qvarianthash.h kernel/qvariantlist.h plugin/qfactoryinterface.cpp plugin/qfactoryinterface.h plugin/qfactoryloader.cpp plugin/qfactoryloader_p.h plugin/qplugin.h plugin/qplugin_p.h diff --git a/src/corelib/io/qdebug.h b/src/corelib/io/qdebug.h index fccf581ed92..32b3bf793dc 100644 --- a/src/corelib/io/qdebug.h +++ b/src/corelib/io/qdebug.h @@ -41,14 +41,9 @@ #ifndef QDEBUG_H #define QDEBUG_H -#include -#include -#include -#include +#include #include #include -#include -#include #include #include @@ -58,6 +53,13 @@ #include #include +#if !defined(QT_LEAN_HEADERS) || QT_LEAN_HEADERS < 1 +# include +# include +# include +# include +#endif + QT_BEGIN_NAMESPACE class QT6_ONLY(Q_CORE_EXPORT) QDebug : public QIODeviceBase diff --git a/src/corelib/kernel/qvariant.h b/src/corelib/kernel/qvariant.h index fc6b8e95634..ffc091ebf96 100644 --- a/src/corelib/kernel/qvariant.h +++ b/src/corelib/kernel/qvariant.h @@ -41,23 +41,22 @@ #define QVARIANT_H #include -#include -#include +#include #include -#include -#include -#include -#include -#include #ifndef QT_NO_DEBUG_STREAM #include #endif -#ifndef QT_BOOTSTRAPPED -#include -#endif #include #include #include +#if !defined(QT_LEAN_HEADERS) || QT_LEAN_HEADERS < 1 +# include +# include +# include +# include +# include +# include +#endif QT_BEGIN_NAMESPACE diff --git a/src/corelib/kernel/qvarianthash.h b/src/corelib/kernel/qvarianthash.h new file mode 100644 index 00000000000..3ace02eede2 --- /dev/null +++ b/src/corelib/kernel/qvarianthash.h @@ -0,0 +1,56 @@ +/**************************************************************************** +** +** Copyright (C) 2022 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtCore module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QVARIANTHASH_H +#define QVARIANTHASH_H + +#if 0 +#pragma qt_class(QVariantHash) +#endif + +#include + +#include +#include +#include + +QT_BEGIN_NAMESPACE +QT_END_NAMESPACE + +#endif diff --git a/src/corelib/kernel/qvariantlist.h b/src/corelib/kernel/qvariantlist.h new file mode 100644 index 00000000000..9cecf2e4848 --- /dev/null +++ b/src/corelib/kernel/qvariantlist.h @@ -0,0 +1,55 @@ +/**************************************************************************** +** +** Copyright (C) 2022 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtCore module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QVARIANTLIST_H +#define QVARIANTLIST_H + +#if 0 +#pragma qt_class(QVariantList) +#endif + +#include + +#include +#include + +QT_BEGIN_NAMESPACE +QT_END_NAMESPACE + +#endif diff --git a/src/corelib/kernel/qvariantmap.h b/src/corelib/kernel/qvariantmap.h new file mode 100644 index 00000000000..a2d04589021 --- /dev/null +++ b/src/corelib/kernel/qvariantmap.h @@ -0,0 +1,56 @@ +/**************************************************************************** +** +** Copyright (C) 2022 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtCore module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QVARIANTMAP_H +#define QVARIANTMAP_H + +#if 0 +#pragma qt_class(QVariantMap) +#endif + +#include + +#include +#include +#include + +QT_BEGIN_NAMESPACE +QT_END_NAMESPACE + +#endif diff --git a/src/corelib/tools/qsharedpointer_impl.h b/src/corelib/tools/qsharedpointer_impl.h index 1b982c0cf90..683dc496a40 100644 --- a/src/corelib/tools/qsharedpointer_impl.h +++ b/src/corelib/tools/qsharedpointer_impl.h @@ -62,13 +62,17 @@ QT_END_NAMESPACE #include #include -#include // for qobject_cast #include +#include // for IsPointerToTypeDerivedFromQObject #include QT_BEGIN_NAMESPACE +class QObject; +template +T qobject_cast(const QObject *object); + // // forward declarations // diff --git a/sync.profile b/sync.profile index 83fab8ffe05..70f652ecf40 100644 --- a/sync.profile +++ b/sync.profile @@ -51,7 +51,6 @@ "qevent.h" => "QtEvents", "qnamespace.h" => "Qt", "qnumeric.h" => "QtNumeric", - "qvariant.h" => "QVariantHash,QVariantList,QVariantMap", "qvulkanfunctions.h" => "QVulkanFunctions,QVulkanDeviceFunctions", "qgl.h" => "QGL", "qtsqlglobal.h" => "QSql",