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

--- Comment #14 from Marc Glisse <glisse at gcc dot gnu.org> ---
(In reply to Arthur O'Dwyer from comment #13)
> Re https://gcc.gnu.org/viewcvs?rev=266386&root=gcc&view=rev — awesome, but
> I'm curious: Why `deque<T>` before `vector<T>`?
> I mean are you planning eventually to add the specializations of
> `__is_trivially_relocatable` for `vector`, `forward_list`,
> `reference_wrapper`, `optional`, `pair`, etc. etc., and you just decided to
> start with `deque`? or was there a specific motivating case?

Because deque is not noexcept-move-constructible. This means that by default it
cannot execute the destructors right after the move constructors, so it does
not have a chance to remove the unnecessary allocation. We really need to help
it at the library level, and the potential gain is significant.
For vector, the compiler sees a loop copying contiguous data from one place to
another, so it should be able to produce a call to memcpy without help: PR
86024. There may be complications related to aliasing, I haven't looked at it
yet. But I believe we should first explore making the compiler more clever,
which would apply to a lot of code, before optimizing a special case in one
library (which we could still do as a stopgap).
I expect we may add some specializations for wrapper types like
pair/tuple/optional/etc because we don't have compiler support to automatically
handle them (like your attribute), although I am not sure how far we should go
(without compiler support). Specializing for one type was a bit of a proof of
concept, checking that the code was ready for it, it isn't a promise to
specialize a lot more. I do still hope some version of destructive move will
eventually be standardized and resolve the issue.

This is all just my opinion, it may change, and others (in particular the
maintainers) may have a different opinion.

By the way, there won't be anything new for several months, this is gcc's
hibernation season where it tries to properly digest all it has eaten during
the summer.

Reply via email to