From c7af8d580873f1d32f561455aa080b367dc38135 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Fri, 7 Oct 2022 08:47:35 +0200 Subject: [PATCH] Deprecate qAsConst() std::as_const() is a 100% equivalent replacement. [ChangeLog][Deprecation Notices][QtCore] qAsConst() is now deprecated. You can simply globally search and replace "qAsConst" with "std::as_const" in your code-base. Change-Id: If9b29f9b4119cf5bdb9f0a1ada1271c6bb503916 Reviewed-by: Volker Hilsheimer Reviewed-by: Thiago Macieira Reviewed-by: Qt CI Bot --- src/corelib/global/qttypetraits.h | 4 ++++ src/corelib/global/qttypetraits.qdoc | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/src/corelib/global/qttypetraits.h b/src/corelib/global/qttypetraits.h index a7bb4e5353..49f2728e9f 100644 --- a/src/corelib/global/qttypetraits.h +++ b/src/corelib/global/qttypetraits.h @@ -5,6 +5,7 @@ #define QTTYPETRAITS_H #include +#include #include #include @@ -24,14 +25,17 @@ constexpr std::underlying_type_t qToUnderlying(Enum e) noexcept } #ifndef QT_NO_AS_CONST +#if QT_DEPRECATED_SINCE(6, 6) // this adds const to non-const objects (like std::as_const) template +QT_DEPRECATED_VERSION_X_6_6("Use std::as_const() instead.") constexpr typename std::add_const::type &qAsConst(T &t) noexcept { return t; } // prevent rvalue arguments: template void qAsConst(const T &&) = delete; +#endif // QT_DEPRECATED_SINCE(6, 6) #endif // QT_NO_AS_CONST #ifndef QT_NO_QEXCHANGE diff --git a/src/corelib/global/qttypetraits.qdoc b/src/corelib/global/qttypetraits.qdoc index 082b6255a1..44c9ad685c 100644 --- a/src/corelib/global/qttypetraits.qdoc +++ b/src/corelib/global/qttypetraits.qdoc @@ -15,6 +15,8 @@ \relates \since 5.7 + \deprecated [6.6] Use std::as_const() instead. + Returns \a t cast to \c{const T}. This function is a Qt implementation of C++17's std::as_const(), @@ -52,6 +54,8 @@ \since 5.7 \overload + \deprecated [6.6] + This overload is deleted to prevent a dangling reference in code like \snippet code/src_corelib_global_qglobal.cpp as-const-4 */