FStringView constexpr constructor fails due to non-constexpr TCString::Strlen

Hello.

I ran into an issue in the following code, where sv cannot be declared constexpr:

// error: constexpr variable 'sv' must be initialized by a constant expression constexpr auto sv = FStringView(TEXT("foo"));

This happens because TCString<T>::Strlen(const CharType*) is not marked constexpr.

Although TStringView::TStringView(const CharType*) is itself marked constexpr, it can never produce a compile-time constant since it calls the non-constexpr TCString<T>::Strlen(const CharType*).

Therefore, either:

  1. Remove the constexpr from TStringView::TStringView(const CharType*),
  2. Or mark TCString<T>::Strlen(const CharType* String) as constexpr.

The latter would require making FPlatformString::Strlen constexpr‐capable. On C++17 and later, that should really resolve to std::char_traits<TCHAR>::length, which is a constexpr function.

I forgot to break line sry :sweat_smile: (and I don’t have permission to edit my first post :rofl:)

// error: constexpr variable 'sv' must be initialized by a constant expression
constexpr auto sv = FStringView(TEXT("foo"));