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

--- Comment #9 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Marc Mutz from comment #7)
> > v.emplace(v.begin(), std::string_view(v[1]));
> 
> That shouldn't actually copy, since it's an rvalue you're passing, and
> rvalues ought not alias members of the containers

I don't think the standard says that. [res.on.arguments] talks about a unique
reference *to the argument* and that's certainly true here. Nothing else has a
reference to the string_view prvalue. It can still alias container elements
though.

There's absolutely no difference between the case above and this one:
string_view s(v[1]);
v.emplace(v.begin(), s);

Both alias an element of the container, and with a different type. That's why I
used string_view not just a string&. The string_view case defeats any checks
for the argument being a value_type& but it still aliases one of the vector's
elements.

Reply via email to