summaryrefslogtreecommitdiffstats
path: root/src/corelib/text
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@qt.io>2024-02-21 14:33:59 +0100
committerMarc Mutz <marc.mutz@qt.io>2024-03-02 00:12:55 +0100
commit4b806d678e68c786f4be3809c72d396ae15bb04c (patch)
treee4e7ad32f75df9c08c6e0adaae384b05a10eb0c7 /src/corelib/text
parent97bbf37f42f160e8c3b6d9d0decc21425d25d70a (diff)
Rename qIsConstantEvaluated() to q20::is_constant_evaluated()
We should really try to avoid another almost-std-compatible-but-not-quite idiom. When qIsConstantEvaluated() was added, the rationale was given that this cannot be q20, because we can't implement it in all compilers. But we can: returning false is a perfectly legal implementation, and makes most users actually simpler because the #ifdef'ery can be dropped. There are only two users that still require the macro, because either they do different fallbacks depending on whether the implementation is trivial, or because they direct expected test outcomes. The INTEGRITY compiler complains "calling __has_builtin() in a constant expression", which we currently don't understand. To unblock this patch, and therefore the 6.7 release, hard-code INTEGRITY to return false. Amends 95e6fac0a5a1eee3aa23e4da0a93c6c25e32fb98. Pick-to: 6.7 Change-Id: If6cae902ff434f2ccceb6057cb053b7f304a604c Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Ivan Solovev <ivan.solovev@qt.io> Reviewed-by: Ahmad Samir <a.samirh78@gmail.com> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Diffstat (limited to 'src/corelib/text')
-rw-r--r--src/corelib/text/qanystringview.h12
-rw-r--r--src/corelib/text/qstringalgorithms.h6
-rw-r--r--src/corelib/text/qstringview.h4
3 files changed, 7 insertions, 15 deletions
diff --git a/src/corelib/text/qanystringview.h b/src/corelib/text/qanystringview.h
index b7f3650275..01efd83743 100644
--- a/src/corelib/text/qanystringview.h
+++ b/src/corelib/text/qanystringview.h
@@ -102,12 +102,7 @@ private:
static constexpr bool isAsciiOnlyCharsAtCompileTime(Char *str, qsizetype sz) noexcept
{
// do not perform check if not at compile time
-#if !defined(QT_SUPPORTS_IS_CONSTANT_EVALUATED)
- Q_UNUSED(str);
- Q_UNUSED(sz);
- return false;
-#else
- if (!qIsConstantEvaluated())
+ if (!q20::is_constant_evaluated())
return false;
if constexpr (sizeof(Char) != sizeof(char)) {
Q_UNUSED(str);
@@ -120,7 +115,6 @@ private:
}
return true;
}
-#endif
}
template<typename Char>
@@ -138,10 +132,8 @@ private:
template <typename Char>
static constexpr qsizetype lengthHelperPointer(const Char *str) noexcept
{
-#ifdef QT_SUPPORTS_IS_CONSTANT_EVALUATED
- if (qIsConstantEvaluated())
+ if (q20::is_constant_evaluated())
return qsizetype(std::char_traits<Char>::length(str));
-#endif
if constexpr (sizeof(Char) == sizeof(char16_t))
return QtPrivate::qustrlen(reinterpret_cast<const char16_t*>(str));
else
diff --git a/src/corelib/text/qstringalgorithms.h b/src/corelib/text/qstringalgorithms.h
index 320a08737d..84c104eafd 100644
--- a/src/corelib/text/qstringalgorithms.h
+++ b/src/corelib/text/qstringalgorithms.h
@@ -16,6 +16,8 @@
#include <string.h> // for memchr
+#include <QtCore/q20type_traits.h> // q20::is_constant_evaluated
+
QT_BEGIN_NAMESPACE
namespace QtPrivate {
@@ -169,7 +171,7 @@ lengthHelperContainer(const Char (&str)[N])
return str[0] == Char(0) ? 0 : 1;
} else if constexpr (N > RuntimeThreshold) {
#ifdef QT_SUPPORTS_IS_CONSTANT_EVALUATED
- if (!qIsConstantEvaluated())
+ if (!q20::is_constant_evaluated())
return QtPrivate::qustrnlen(reinterpret_cast<const char16_t *>(str), N);
#endif
}
@@ -181,7 +183,7 @@ template <typename Char, size_t N> [[nodiscard]] constexpr inline
std::enable_if_t<sizeof(Char) == 1, qsizetype> lengthHelperContainer(const Char (&str)[N])
{
#ifdef QT_SUPPORTS_IS_CONSTANT_EVALUATED
- if (!qIsConstantEvaluated())
+ if (!q20::is_constant_evaluated())
return qstrnlen(reinterpret_cast<const char *>(str), N);
#endif
diff --git a/src/corelib/text/qstringview.h b/src/corelib/text/qstringview.h
index 048c1b005d..742ecadcf5 100644
--- a/src/corelib/text/qstringview.h
+++ b/src/corelib/text/qstringview.h
@@ -104,10 +104,8 @@ private:
template <typename Char>
static constexpr qsizetype lengthHelperPointer(const Char *str) noexcept
{
-#if defined(QT_SUPPORTS_IS_CONSTANT_EVALUATED)
- if (qIsConstantEvaluated())
+ if (q20::is_constant_evaluated())
return std::char_traits<Char>::length(str);
-#endif
return QtPrivate::qustrlen(reinterpret_cast<const char16_t *>(str));
}
static qsizetype lengthHelperPointer(const QChar *str) noexcept