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

**URL:** <https://forums.unrealengine.com/t/fstringview-constexpr-constructor-fails-due-to-non-constexpr-tcstring-strlen/2499036>\
**Category:** Programming & Scripting\
**Tags:** string, unreal-engine, issue, CPP\
**Created:** [May 9, 2025, 2:22pm UTC](https://forums.unrealengine.com/t/fstringview-constexpr-constructor-fails-due-to-non-constexpr-tcstring-strlen/2499036 "2025-05-09T14:22:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Masaya\_Sakai](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Masaya\_Sakai](https://forums.unrealengine.com/u/Masaya_Sakai)\
**Post date:** [May 9, 2025, 2:22pm UTC](https://forums.unrealengine.com/t/fstringview-constexpr-constructor-fails-due-to-non-constexpr-tcstring-strlen/2499036/1 "2025-05-09T14:22:21Z")

</div>

Hello.

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

```cpp
// 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.

---

<div class="post-metadata">

**Author:** ![Masaya\_Sakai](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Masaya\_Sakai](https://forums.unrealengine.com/u/Masaya_Sakai)\
**Post date:** [May 15, 2025, 2:25am UTC](https://forums.unrealengine.com/t/fstringview-constexpr-constructor-fails-due-to-non-constexpr-tcstring-strlen/2499036/2 "2025-05-15T02:25:10Z")

</div>

I forgot to break line sry 😅 (and I don’t have permission to edit my first post 🤣)

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

```
