https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99805
--- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> --- It would have worked if it used std::as_const(_M_pathname).data() or _M_pathname.c_str() instead of _M_pathname.data(). It's only the non-const data() added in C++17 which reallocates (since r261642 anyway).