https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111258
Jiang An <de34 at live dot cn> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |de34 at live dot cn --- Comment #2 from Jiang An <de34 at live dot cn> --- Perhaps this is a compiler bug and there's nothing wrong in the move constructor. GCC 13 also incorrectly rejects the following program (https://godbolt.org/z/Yn98KMKv5) ``` #include <string> constexpr bool foo11(std::string s) { s.push_back('\0'); return true; } int main() { static_assert(foo11(std::string{})); } ``` with similar message: ``` <source>: In function 'int main()': <source>:12:24: error: non-constant condition for static assertion 12 | static_assert(foo11(std::string{})); | ~~~~~^~~~~~~~~~~~~~~ <source>:12:24: in 'constexpr' expansion of 'foo11(std::__cxx11::basic_string<char>())' <source>:5:16: in 'constexpr' expansion of 's.std::__cxx11::basic_string<char>::push_back(0)' /opt/compiler-explorer/gcc-13.2.0/include/c++/13.2.0/bits/basic_string.h:1552:33: in 'constexpr' expansion of '((std::__cxx11::basic_string<char>*)this)->std::__cxx11::basic_string<char>::capacity()' <source>:12:24: 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 Compiler returned: 1 ``` It seems that gcc currently miscompiles passing-by-value of non-trivially-copyable classes in constant evaluation.