Created attachment 53318 [details] Log produced by Compiler Explorer when using gcc (trunk) The following code produces a warning under `-std=c++20 -O3 -Wrestrict`: #include <string> std::string memcpy_bug() { return "x" + std::string("yz"); } (1) If `"x"` is changed to be a string literal of any length other than 1, the warning does not occur (2) If `std::string("yz")` is pulled out into a variable (i.e. `std::string var("yz");` and `return "x" + var;`) the warning does not occur (3) If the optimization mode used is O1, O2, or Os, the warning does not occur (4) If the compiler version is downgraded to GCC 11.3, the warning does not occur Appending a length-1 literal does not have this issue. Attached is the log produced by Compiler Explorer on GCC trunk commit c70a48a8f8f6a43b35f783b5672c9a3c0a363c31. Possibly related to <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105329>. I made the decision to submit this independently due to (2), but I don't doubt that it's likely a duplicate.
I think it is a dup of that one.
Dup of bug 105651. *** This bug has been marked as a duplicate of bug 105651 ***