https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79349
--- Comment #4 from Marc Glisse <glisse at gcc dot gnu.org> --- With the call to foo(), this is an issue of alias analysis. Gcc wrongly believes that the string escapes (probably because we store a pointer to the string inside the string itself, with the small string optimization), and thus that foo() might modify the string, so it needs to check if the destructor needs to run, whether foo returns normally or throws an exception.