summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2022-02-10 11:20:25 -0800
committerMarc Mutz <marc.mutz@qt.io>2022-02-12 07:59:32 +0000
commit4fd4082c3ab682f14911e6308ec5ccb400de34f9 (patch)
tree32cc57a50f80d34b14fa0db733a1766ec54cfdd7
parent98de89cc1569be25e9845fe99ada76342aa27ad9 (diff)
QStringView: add missing constexpr so we can use is_constant_evaluated
GCC 12 -std=c++20 says: qstringview.h:155:39: error: ‘std::is_constant_evaluated’ always evaluates to false in a non-‘constexpr’ function [-Werror=tautological-compare] With this, it's possible to declare: constexpr QStringView sv = u"Hello, World!"; QStringView f() { return sv; } And GCC will generate: movl $13, %eax leaq .LC0(%rip), %rdx ret Writing simply QStringView f() { return u"Hello, World!"; } Causes GCC to emit a comparison loop (the std::char_traits::length function), but at least there's no function call in either C++17 or 20. Clang 13 is able to reduce the loop to a constant and produces the same code as the constexpr variable in either mode. Pick-to: 5.15 6.2 6.3 Change-Id: I74249c52dc02478ba93cfffd16d282fa35a5b883 Reviewed-by: Marc Mutz <marc.mutz@qt.io>
-rw-r--r--src/corelib/text/qstringview.h2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/corelib/text/qstringview.h b/src/corelib/text/qstringview.h
index 5d05dd6edd..f229df9c21 100644
--- a/src/corelib/text/qstringview.h
+++ b/src/corelib/text/qstringview.h
@@ -149,7 +149,7 @@ private:
using if_compatible_container = typename std::enable_if<QtPrivate::IsContainerCompatibleWithQStringView<T>::value, bool>::type;
template <typename Char>
- static qsizetype lengthHelperPointer(const Char *str) noexcept
+ static constexpr qsizetype lengthHelperPointer(const Char *str) noexcept
{
#if defined(__cpp_lib_is_constant_evaluated)
if (std::is_constant_evaluated())