[Bug middle-end/98465] Bogus -Wstringop-overread with -std=gnu++20 -O2 and std::string::insert

Randy at miningrigrentals dot com gcc-bugzilla@gcc.gnu.org
Tue Feb 15 19:23:02 GMT 2022


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98465

--- Comment #42 from Randy <Randy at miningrigrentals dot com> ---
(In reply to Jonathan Wakely from comment #41)
> So then basically the same as what I said:
> 
> (In reply to Jonathan Wakely from comment #37)
> > (Your segfaults are probably because you're using c_str() on a temporary
> > string, so accessing the pointer after the temporary goes out of scope.)
> 
> You're relying on the string contents outliving a specific object, which
> only works if the contents are reference-counted and there is still another
> object somewhere that owns it. Your code has a bug.
This isn't the place to discuss this.

vstring solved the problem I was having at the time and I don't know if its
still an issue. Might have been using gcc-4.8.x at the time and I think
std::string implementation changed since then. I have no reason to switch from
using vstring, I just want those who work on gcc to also consider updating
vstring with the same type of fixes for this warning.


More information about the Gcc-bugs mailing list