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

--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Jonathan Wakely from comment #2)
> We end up in the new replace() overload when we should be in the const char*
> one here:
> 
>     basic_string&
>     replace(size_type __pos, size_type __n, const basic_string& __str)
>     { return this->replace(__pos, __n, __str._M_data(), __str.size()); }

We could fix Tobias's example by changing this to use c_str() instead of
_M_data(), which would pass a const char* and so call the desired overload.

That wouldn't help comment 3 though, where a (non-const) char* is passed
directly, which requires a conversion to call the overload for const char*, and
so the new overload taking a string_view is chosen by overload resolution.

With the new overload str.replace(0, 1, &c, 1) is equivalent to str.replace(0,
1, string_view{&c, 1}, 1) which replaces the specified substring with
string_view{&c, 1}.substr(1) rather than string_view{&c, 1}.

Reply via email to