diff --git a/.cmake.conf b/.cmake.conf index 4f4c0a20174..979edb2e37e 100644 --- a/.cmake.conf +++ b/.cmake.conf @@ -5,6 +5,7 @@ # (directly by qtbase) we actually add the extra definitions if (NOT DEFINED QT_SUPERBUILD OR DEFINED QT_REPO_MODULE_VERSION) set(QT_EXTRA_INTERNAL_TARGET_DEFINES "QT_LEAN_HEADERS=1") + list(APPEND QT_EXTRA_INTERNAL_TARGET_DEFINES "QT_NO_AS_CONST=1") endif() set(QT_REPO_MODULE_VERSION "6.5.0") diff --git a/src/corelib/global/qttypetraits.h b/src/corelib/global/qttypetraits.h index 1832a1a7344..e8939e7d5ff 100644 --- a/src/corelib/global/qttypetraits.h +++ b/src/corelib/global/qttypetraits.h @@ -23,6 +23,8 @@ constexpr std::underlying_type_t qToUnderlying(Enum e) noexcept return static_cast>(e); } +#ifndef QT_NO_AS_CONST + // this adds const to non-const objects (like std::as_const) template constexpr typename std::add_const::type &qAsConst(T &t) noexcept { return t; } @@ -30,6 +32,8 @@ constexpr typename std::add_const::type &qAsConst(T &t) noexcept { return t; template void qAsConst(const T &&) = delete; +#endif // QT_NO_AS_CONST + // like std::exchange template constexpr T qExchange(T &t, U &&newValue) diff --git a/src/gui/painting/qpdf.cpp b/src/gui/painting/qpdf.cpp index 8d2e6aabc98..02fd2fdeea1 100644 --- a/src/gui/painting/qpdf.cpp +++ b/src/gui/painting/qpdf.cpp @@ -1790,7 +1790,7 @@ void QPdfEnginePrivate::writeDestsRoot() QHash destObjects; QByteArray xs, ys; - for (const DestInfo &destInfo : qAsConst(destCache)) { + for (const DestInfo &destInfo : std::as_const(destCache)) { int destObj = addXrefEntry(-1); xs.setNum(static_cast(destInfo.coords.x()), 'f'); ys.setNum(static_cast(destInfo.coords.y()), 'f'); @@ -1808,7 +1808,7 @@ void QPdfEnginePrivate::writeDestsRoot() xprintf(" "); printString(anchors.constLast()); xprintf("]\n/Names [\n"); - for (const QString &anchor : qAsConst(anchors)) { + for (const QString &anchor : std::as_const(anchors)) { printString(anchor); xprintf(" %d 0 R\n", destObjects[anchor]); } diff --git a/tests/auto/widgets/widgets/qsplitter/tst_qsplitter.cpp b/tests/auto/widgets/widgets/qsplitter/tst_qsplitter.cpp index cbc1a258de7..ec3df1f03dc 100644 --- a/tests/auto/widgets/widgets/qsplitter/tst_qsplitter.cpp +++ b/tests/auto/widgets/widgets/qsplitter/tst_qsplitter.cpp @@ -920,7 +920,7 @@ void tst_QSplitter::task187373_addAbstractScrollAreas_data() "QTreeView" }; - for (const auto &className : qAsConst(classNames)) { + for (const auto &className : std::as_const(classNames)) { QTest::newRow(qPrintable(className + " 1")) << className << false << true; QTest::newRow(qPrintable(className + " 2")) << className << true << false; QTest::newRow(qPrintable(className + " 3")) << className << true << true;