https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116494
--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> --- (In reply to Архипов Дмитрий from comment #0) > When compiled with -std=c++20 -O3 -Wall -Werror this code: > > #include <string> > > bool foo(std::string s1) > { > s1.replace(1, 1, s1.data(), s1.size()); > return s1.size(); > } > > fails with a warning about incorrect use of __builtin_memcpy. As far as I > can see, inside _M_replace the call to _M_disjunct paradoxically determines > that s1.data() is not contained in s1's buffer. Because of that _M_replace > then uses the wrong branch and uses memcpy, when it shouldn't have. No, it doesn't. It's just a warning during compilation. The branch is not taken under those conditions.