https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121707
Bug ID: 121707 Summary: Compiler spills std::string internals when used in consteval context Product: gcc Version: 15.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: dascandy at gmail dot com Target Milestone: --- When compiling the below source code #include <string> template <typename = void> struct T { static constexpr std::string value{}; }; void f() { T<>::value; } the compiler fails on the line in f() with the following error referring to the members of the std::string being private: <source>:5:34: error: 'std::__cxx11::basic_string<char>::<unnamed union> std::__cxx11::basic_string<char>::<anonymous>' is private within this context 5 | static constexpr std::string value{}; | ^~~~~ In file included from /cefs/b6/b615954805438726f22a60c9_converted_gcc-15.2.0/include/c++/15.2.0/string:56, from <source>:1: /cefs/b6/b615954805438726f22a60c9_converted_gcc-15.2.0/include/c++/15.2.0/bits/basic_string.h:220:7: note: declared private here 220 | union | ^~~~~ <source>:5:34: error: 'char std::__cxx11::basic_string<char>::<unnamed union>::_M_local_buf [16]' is private within this context 5 | static constexpr std::string value{}; | ^~~~~ /cefs/b6/b615954805438726f22a60c9_converted_gcc-15.2.0/include/c++/15.2.0/bits/basic_string.h:222:26: note: declared private here 222 | _CharT _M_local_buf[_S_local_capacity + 1]; | ^~~~~~~~~~~~ The same code works fine in Clang. Checked with `-std=c++26`. https://godbolt.org/z/844x68798