[PATCH] libstdc++: Simplify std::vector::vector(from_range_t, const Alloc&)
Jonathan Wakely
jwakely@redhat.com
Fri Mar 21 22:59:57 GMT 2025
On Thu, 20 Mar 2025 at 18:53, Jonathan Wakely <jwakely@redhat.com> wrote:
>
> Tomasz suggested replacing this constructor with just append_range(rg),
> after using a delegating constructor so that the destructor will run if
> append_range exits via an exception.
>
> This is slightly less simple than his suggestion, because I want to
> avoid the overhead of reserve's slow path and the ASan annotations.
> Neither of those is needed for this constructor, because we have no
> existing storage to reallocate and no unused capacity to tell ASan
> about.
>
> libstdc++-v3/ChangeLog:
>
> * include/bits/stl_vector.h (vector(from_range_t, Alloc)): Use
> delegating constructor instead of RAII guards. Use append_range
> for unsized input range case.
I need to revert this, and then fix append_range.
The standard allows append_range to be used with an overlapping range,
e.g. v.append_range(v).
That means we can't reallocate the existing storage until after
copying from the range. The constructor doesn't have that restriction
(there are no existing elements) so it doesn't make sense to implement
the constructor in terms of the more complex append_range.
I'm testing a fix, but will send it on Monday.
More information about the Libstdc++
mailing list