https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98465
--- Comment #20 from Jakub Jelinek <jakub at gcc dot gnu.org> --- What I meant this as was a variant to Martin's the https://gcc.gnu.org/pipermail/gcc/2021-January/234641.html idea. Or perhaps add an attribute on _M_dataplus._M_p member that would tell the compiler about this special behavior (the containing class owns the pointer, and it can point either to a heap allocated memory that is owned by the class, or can point into a local buffer within the same object as the pointer, and let have the new *disjunct builtin be for now the only consumer of that attribute. It could then handle both the case where the _M_replace __s points to a variable that clearly can't be owned by the string object, but perhaps also when passed pointers to other string objects (it would see, the other pointer is loaded from _M_dataplus._M_p that has this new magic attribute, so the containing object owns that pointer, and if points-to analysis finds out it can't alias with the other owning object, it could fold the disjunct builtin to false too. The problem is that the else part in if (_M_disjunct(...)) { ... } else { ... } is large, complicated and prone to these false positive warnings, so it is desirable to fold _M_disjunct to compile time false as much as possible. I have really no idea how often in real-world code people actually pass parts of the destination string as the source (i.e. how often _M_disjunct returns true). Maybe if it is very rare another alternative would be avoid inlining that (either by moving it into a separate method with noinline, cold attributes or perhaps to a helper function in libstdc++ library.