https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118285
Bug ID: 118285 Summary: GCC rejects some constexpr std::string usages Product: gcc Version: 15.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: dangelog at gmail dot com Target Milestone: --- Hi, This is a spin-off of PR103924. The following testcase is rejected by GCC rejected by GCC but accepted by Clang (with libstdc++): https://gcc.godbolt.org/z/63Wss3Ej8 #include <string> constexpr void f(std::initializer_list<std::string>) {} constexpr bool test() { f({"x"}); return true; } static_assert(test()); <source>:10:19: error: non-constant condition for static assertion 10 | static_assert(test()); | ~~~~^~ In file included from /opt/compiler-explorer/gcc-14.2.0/include/c++/14.2.0/string:54, from <source>:1: <source>:10:19: in 'constexpr' expansion of 'test()' <source>:6:6: in 'constexpr' expansion of '((std::__cxx11::basic_string<char>*)<anonymous>)->std::__cxx11::basic_string<char>::~basic_string()' /opt/compiler-explorer/gcc-14.2.0/include/c++/14.2.0/bits/basic_string.h:809:19: in 'constexpr' expansion of '((std::__cxx11::basic_string<char>*)this)->std::__cxx11::basic_string<char>::_M_dispose()' /opt/compiler-explorer/gcc-14.2.0/include/c++/14.2.0/bits/basic_string.h:288:22: 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 288 | _M_destroy(_M_allocated_capacity); | ^~~~~~~~~~~~~~~~~~~~~ Compiler returned: 1 I've been trying to minimize the testcase by removing clutter from basic_string: https://gcc.godbolt.org/z/haxvvr1YK The fun part is that if one deletes the copy constructor (which is actually never called) the code is accepted by GCC. That's what makes me think this is a compiler bug.