From 418409aa6f85724ed3731b21117d46d13efcc6a2 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Fri, 4 Jul 2025 08:39:08 -0400 Subject: [PATCH] AK: Fix usage of constexpr within Utf16View and related utilities * Error and ErrorOr are not themelves constexpr, so a function returning these types cannot be constexpr. * The UDL was trying to call Utf16View::validate, which is not constexpr itself. The compiler will actually already raise an error if a UTF-16 literal is invalid, so let's just avoid the call altogether. --- AK/UnicodeUtils.h | 2 +- AK/Utf16View.h | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/AK/UnicodeUtils.h b/AK/UnicodeUtils.h index 3d037c6275c..519426e6fe4 100644 --- a/AK/UnicodeUtils.h +++ b/AK/UnicodeUtils.h @@ -137,7 +137,7 @@ template } template Callback> -constexpr ErrorOr try_code_point_to_utf16(u32 code_point, Callback callback) +ALWAYS_INLINE ErrorOr try_code_point_to_utf16(u32 code_point, Callback callback) { if (code_point < FIRST_SUPPLEMENTARY_PLANE_CODE_POINT) { TRY(callback(static_cast(code_point))); diff --git a/AK/Utf16View.h b/AK/Utf16View.h index 0c396983ac2..910544df74e 100644 --- a/AK/Utf16View.h +++ b/AK/Utf16View.h @@ -88,7 +88,7 @@ public: } private: - Utf16CodePointIterator(char16_t const* ptr, size_t length) + constexpr Utf16CodePointIterator(char16_t const* ptr, size_t length) : m_iterator(ptr) , m_remaining_code_units(length) { @@ -346,9 +346,7 @@ struct Traits : public DefaultTraits { [[nodiscard]] ALWAYS_INLINE AK_STRING_VIEW_LITERAL_CONSTEVAL AK::Utf16View operator""sv(char16_t const* string, size_t length) { - AK::Utf16View view { string, length }; - ASSERT(view.validate()); - return view; + return { string, length }; } #if USING_AK_GLOBALLY