From ed898efac7806a711929eaef3bc3090550498b6f Mon Sep 17 00:00:00 2001 From: Ivan Solovev Date: Tue, 27 Feb 2024 14:28:32 +0100 Subject: [PATCH] Bring back QASV::detects_US_ASCII_at_compile_time Even though undocumented, it's public API, doesn't hurt to carry along, and improves compiler coverage in the test, so let's not remove it. Found in 6.7 API review Amends 95e6fac0a5a1eee3aa23e4da0a93c6c25e32fb98. Change-Id: Ia935036a69e0e678f22ac86b48a2c1c5e8c46733 Reviewed-by: Marc Mutz (cherry picked from commit 380c01bac545172624944e269214ba168e59fb3c) Reviewed-by: Qt Cherry-pick Bot --- src/corelib/text/qanystringview.h | 8 ++++++++ .../corelib/text/qanystringview/tst_qanystringview.cpp | 8 +++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/corelib/text/qanystringview.h b/src/corelib/text/qanystringview.h index e947ea7fc72..0d064c6cd38 100644 --- a/src/corelib/text/qanystringview.h +++ b/src/corelib/text/qanystringview.h @@ -275,6 +275,14 @@ public: [[nodiscard]] Q_CORE_EXPORT static int compare(QAnyStringView lhs, QAnyStringView rhs, Qt::CaseSensitivity cs = Qt::CaseSensitive) noexcept; [[nodiscard]] Q_CORE_EXPORT static bool equal(QAnyStringView lhs, QAnyStringView rhs) noexcept; + static constexpr inline bool detects_US_ASCII_at_compile_time = +#ifdef QT_SUPPORTS_IS_CONSTANT_EVALUATED + true +#else + false +#endif + ; + // // STL compatibility API: // diff --git a/tests/auto/corelib/text/qanystringview/tst_qanystringview.cpp b/tests/auto/corelib/text/qanystringview/tst_qanystringview.cpp index b4f5d53373d..6c29ac1cc24 100644 --- a/tests/auto/corelib/text/qanystringview/tst_qanystringview.cpp +++ b/tests/auto/corelib/text/qanystringview/tst_qanystringview.cpp @@ -570,8 +570,7 @@ void tst_QAnyStringView::debug() const void tst_QAnyStringView::asciiLiteralIsLatin1() const { -#ifdef QT_SUPPORTS_IS_CONSTANT_EVALUATED - if constexpr (true) { + if constexpr (QAnyStringView::detects_US_ASCII_at_compile_time) { constexpr bool asciiCstringIsLatin1 = QAnyStringView("Hello, World").isLatin1(); QVERIFY(asciiCstringIsLatin1); constexpr bool asciiUtf8stringIsLatin1 = QAnyStringView(u8"Hello, World").isLatin1(); @@ -587,10 +586,9 @@ void tst_QAnyStringView::asciiLiteralIsLatin1() const constexpr bool utf8StringArrayIsNotLatin1 = !QAnyStringView::fromArray(u8"Tørrfisk").isLatin1(); QVERIFY(utf8StringArrayIsNotLatin1); + } else { + QSKIP("Compile-detection of US-ASCII strings not possible with this compiler"); } -#else - QSKIP("Compile-detection of US-ASCII strings not possible with this compiler"); -#endif } template