summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/corelib/global/q20type_traits.h25
-rw-r--r--src/corelib/global/qttypetraits.h17
-rw-r--r--src/corelib/text/qanystringview.h12
-rw-r--r--src/corelib/text/qstringalgorithms.h6
-rw-r--r--src/corelib/text/qstringview.h4
5 files changed, 32 insertions, 32 deletions
diff --git a/src/corelib/global/q20type_traits.h b/src/corelib/global/q20type_traits.h
index 80ac1fa4313..63a453daca8 100644
--- a/src/corelib/global/q20type_traits.h
+++ b/src/corelib/global/q20type_traits.h
@@ -3,6 +3,8 @@
#ifndef Q20TYPE_TRAITS_H
#define Q20TYPE_TRAITS_H
+#include <QtCore/qcompilerdetection.h>
+#include <QtCore/qsystemdetection.h>
#include <QtCore/qtconfigmacros.h>
//
@@ -26,6 +28,29 @@
QT_BEGIN_NAMESPACE
namespace q20 {
+// like std::is_constant_evaluated
+#ifdef __cpp_lib_is_constant_evaluated
+using std::is_constant_evaluated;
+#define QT_SUPPORTS_IS_CONSTANT_EVALUATED
+#else
+constexpr bool is_constant_evaluated() noexcept
+{
+#ifdef Q_OS_INTEGRITY
+ // Integrity complains "calling __has_builtin() from a constant expression".
+ // Avoid the __has_builtin check until we know what's going on.
+ return false;
+#elif __has_builtin(__builtin_is_constant_evaluated) || \
+ (defined(Q_CC_MSVC_ONLY) /* >= 1925, but we require 1927 in qglobal.h */)
+# define QT_SUPPORTS_IS_CONSTANT_EVALUATED
+ return __builtin_is_constant_evaluated();
+#else
+ return false;
+#endif
+}
+#endif // __cpp_lib_is_constant_evaluated
+}
+
+namespace q20 {
// like std::remove_cvref(_t)
#ifdef __cpp_lib_remove_cvref
using std::remove_cvref;
diff --git a/src/corelib/global/qttypetraits.h b/src/corelib/global/qttypetraits.h
index 9129f536aa8..49f2728e9f5 100644
--- a/src/corelib/global/qttypetraits.h
+++ b/src/corelib/global/qttypetraits.h
@@ -17,23 +17,6 @@
QT_BEGIN_NAMESPACE
-// like std::is_constant_evaluated
-#define QT_SUPPORTS_IS_CONSTANT_EVALUATED
-#ifdef __cpp_lib_is_constant_evaluated
-constexpr bool qIsConstantEvaluated() noexcept
-{
- return std::is_constant_evaluated();
-}
-#elif __has_builtin(__builtin_is_constant_evaluated) || \
- (defined(Q_CC_MSVC_ONLY) /* >= 1925, but we require 1927 in qglobal.h */)
-constexpr bool qIsConstantEvaluated() noexcept
-{
- return __builtin_is_constant_evaluated();
-}
-#else
-# undef QT_SUPPORTS_IS_CONSTANT_EVALUATED
-#endif
-
// like std::to_underlying
template <typename Enum>
constexpr std::underlying_type_t<Enum> qToUnderlying(Enum e) noexcept
diff --git a/src/corelib/text/qanystringview.h b/src/corelib/text/qanystringview.h
index b7f3650275f..01efd83743d 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 320a08737d8..84c104eafdb 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 048c1b005d6..742ecadcf5d 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