https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105329
--- Comment #13 from Jakub Jelinek <jakub at gcc dot gnu.org> --- I think this is quite related to the PR98465 discussions. The warning is on dead code, for basic_string at least when using reasonable allocators the _M_dataplus._M_p member will always point either into the _M_local_buf embedded buffer, or to something that has been allocated by the allocator. In particular, it should never point into .rodata objects, or when using a reasonable allocator to global or automatic vars (with the exception of the embedded buffer). There is the _M_disjunct method that returns whether the std::string could overlap with the second argument, if we'd say through some magic attribute on the _M_dataplus._M_p were able to tell the optimizers perhaps through a builtin that there is no overlap, we would optimize away the dead code and be fine (not just for the questionable warnings, but more importantly for code generation as well). Another approach to deal with this exact case might be some builtin that would find out if the argument must be in read-only memory ("5" in this case) and use that as an additional check in _M_disjunct, say that then the arg must be read-only, it must be disjunct because the string is necessarily writable. As has been discussed, yet another possibility would be to handle the rare case (not disjunct) in out of line (ideally libstdc++.so.6 contained (at least for the usual instantiations)) code, which would also make the rare case smaller and such warnings not really visible to the optimizers.