[Bug libstdc++/83982] [6/7/8/9 Regression] Exception guarantee of C++14 vector::resize(size_type) is not met
redi at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Wed Jun 13 23:42:00 GMT 2018
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83982
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |ASSIGNED
Known to work| |5.5.0
Assignee|unassigned at gcc dot gnu.org |redi at gcc dot gnu.org
Summary|Exception guarantee of |[6/7/8/9 Regression]
|C++14 |Exception guarantee of
|vector::resize(size_type) |C++14
|is not met |vector::resize(size_type)
| |is not met
Known to fail| |6.4.0, 7.3.0, 8.1.0, 9.0
--- Comment #6 from Jonathan Wakely <redi at gcc dot gnu.org> ---
This testcase passes when compiled by GCC 5 with no option (because that means
-std=gnu++98 and so elements are copied not moved):
#include <vector>
#include <assert.h>
struct X
{
X() : data(1)
{
if (fail)
throw 1;
}
static bool fail;
std::vector<int> data;
};
bool X::fail = false;
void
test01()
{
std::vector<X> v(2);
X* const addr = &v[0];
bool caught = false;
try {
X::fail = true;
v.resize(v.capacity() + 1); // force reallocation
} catch (int) {
caught = true;
}
assert( caught );
assert( v.size() == 2 );
assert( &v[0] == addr );
// PR libstdc++/83982
assert( ! v[0].data.empty() );
assert( ! v[1].data.empty() );
}
int
main()
{
test01();
}
But it fails when compiled by GCC 6 or later (except in C++98 modes), because
the existing elements are moved from and left empty. That makes this a
regression.
More information about the Gcc-bugs
mailing list