This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug libstdc++/86295] New: Missing exception safety when inserting range into vector
- From: "kristian.spangsege at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Mon, 25 Jun 2018 00:22:51 +0000
- Subject: [Bug libstdc++/86295] New: Missing exception safety when inserting range into vector
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86295
Bug ID: 86295
Summary: Missing exception safety when inserting range into
vector
Product: gcc
Version: 8.0.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libstdc++
Assignee: unassigned at gcc dot gnu.org
Reporter: kristian.spangsege at gmail dot com
Target Milestone: ---
When inserting a range into a `std::vector`, and the copy, or move constructor
for the value type throws at an unfortunate time, some constructed objects of
the value type will never be destroyed.
More specifically, the version of `std::vector::_M_range_insert()`, that is for
forward iterators, has calls to `std::__uninitialized_copy_a()` and
`std::__uninitialized_move_a()` at various places. If I understand correctly,
these functions construct a number of new objects of the value type. After each
such call, the logical size of the vector is then increased by the number of
new objects.
The problem occurs when either `std::__uninitialized_copy_a()` or
`std::__uninitialized_move_a()` throws due to throwing from the copy or move
constructor of the value type. In this case, the logical size of the vector
remains at its prior value, which means that if any objects were created, they
will be forgotten about (leaked).
As far as I can see, a solution would be to the carry out these copy and move
operations one value at a time, and update the logical size after each step.
I am referring to the version of libstdc++ that comes with GCC 8.0.1 here.