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>