https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110158
--- Comment #4 from danakj at orodu dot net --- Here's a repro without the std::string inside a union. It is the SSO union inside the string that causes the error. https://gcc.godbolt.org/z/T8oM8vYnq ``` #include <string> template <class T, class I, class S, class F> constexpr T fold(T init, I i, S s, F f) { while (true) { if (i == s) return init; else init = f(std::move(init), *i++); } } constexpr char v[] = {'a', 'b', 'c'}; static_assert(fold(std::string(), std::begin(v), std::end(v), [](std::string acc, char v) { acc.push_back(v); return acc; }) == "abc"); int main() {} ``` <source>:18:23: error: non-constant condition for static assertion 14 | static_assert(fold(std::string(), std::begin(v), std::end(v), | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 15 | [](std::string acc, char v) { | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 16 | acc.push_back(v); | ~~~~~~~~~~~~~~~~~ 17 | return acc; | ~~~~~~~~~~~ 18 | }) == "abc"); | ~~~^~~~~~~~ <source>:18:32: in 'constexpr' expansion of 'fold(T, I, S, F) [with T = std::__cxx11::basic_string<char>; I = const char*; S = const char*; F = <lambda(std::string, char)>](std::begin<const char, 3>(v), std::end<const char, 3>(v), (<lambda closure object><lambda(std::string, char)>(), <lambda(std::string, char)>()))' <source>:18:32: in 'constexpr' expansion of 'std::__cxx11::basic_string<char>((* & std::move<__cxx11::basic_string<char>&>(init)))' <source>:18:23: error: accessing 'std::__cxx11::basic_string<char>::<unnamed union>::_M_allocated_capacity' member instead of initialized 'std::__cxx11::basic_string<char>::<unnamed union>::_M_local_buf' member in constant expression ASM generation compiler returned: 1