https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112100
--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> --- (In reply to Andrew Pinski from comment #1) > Maybe some how libstdc++ debug mode can catch this > https://gcc.gnu.org/onlinedocs/gcc-13.2.0/libstdc++/manual/manual/ > debug_mode_using.html#debug_mode.using.mode > -D_GLIBCXX_DEBUG Only by adding a "past-the-end character is still null" check to std::string member functions (which ones, all of them? Just accessors that would let you read the null, like c_str, operator[], data etc.?) That would be doable, but sounds pretty expensive.