Hi I think I found libstdc++ bug and I tried to report to Bugzilla but "user account creation has been restricted".
So I'm going to report it here in hope that someone with a account could report it to Bugzilla if they seem it fit. Using gcc 13.2 with -std=c++23 code below (https://godbolt.org/z/Kc36rcMYx) does not compile even if all compile time allocations are freed before returning from compile time context. MSVC is able to compile it. I was suggested elsewhere that it could be some oversight in the SSO implementation. ``` #include <string> #include <functional> #include <algorithm> #include <vector> using namespace std; using namespace std::literals; constexpr auto foo() { const auto vec = vector{ "a"s, "b"s, "c"s }; return ranges::fold_left(vec, ""s, plus{}); } constexpr auto bar() { return foo().size(); } int main() { constexpr auto _ = bar(); // This does not compile } ``` Error message: ``` <source>: In function 'int main()': <source>:19:27: in 'constexpr' expansion of 'bar()' <source>:15:23: in 'constexpr' expansion of 'foo()()' <source>:19:28: in 'constexpr' expansion of 'std::ranges::__fold_left_fn::operator()(_Range&&, _Tp, _Fp) const [with _Range = const std::vector<std::__cxx11::basic_string<char>, std::allocator<std::__cxx11::basic_string<char> > >&; _Tp = std::__cxx11::basic_string<char>; _Fp = std::plus<void>](vec, std::literals::string_literals::operator""s(const char*, std::size_t)(0), (std::plus<void>(), std::plus<void>()))' <source>:19:28: in 'constexpr' expansion of 'std::__cxx11::basic_string<char>((* & std::move<__cxx11::basic_string<char>&>(__init)))' <source>:19:28: 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 19 | constexpr auto _ = bar(); | ^ ``` Miro Palmu