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