https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117655
--- Comment #2 from Mathias Stearn <redbeard0531 at gmail dot com> --- It looks like a similar optimization would make sense for operator=(string&&): https://godbolt.org/z/Wo19fjKeK. It might also make sense to just copy the whole buffer for the local case in operator=(const string&), but the win is probably less than the rval and swap optimizations.