Failing test when run as C++11

Jonathan Wakely jwakely.gcc@gmail.com
Sun May 11 21:12:00 GMT 2014


On 11 May 2014 21:28, Daniel Krügler wrote:
> 2014-05-11 20:56 GMT+02:00 Jonathan Wakely <jwakely@redhat.com>:
>> On further reflection, I think the standard does specify this. C is
>> CopyInsertable into std::vector<C>, therefore we must offer the strong
>> exception-safety guarantee, so must call the copy constructor.
>
> Note that we have resize() here and there seem to be no such
> requirement (compared to push_back for example). This seems to be
> consistent with the
> "strong-exception-guarantee-only-for-single-element-inserts".

I don't think I follow. In N3936 resize(size_type) says:
Remarks: If an exception is thrown other than by the move constructor
of a non-CopyInsertable T
there are no effects.

This says to me that if T is CopyInsertable we must offer the strong
exception-safety guarantee.

Even if I'm misunderstanding something about resize(), couldn't we
easily adapt the test to demonstrate the same problem for push_back()
on a vector with size() == capacity()? Or the same problem for
reserve(capacity()+1)?

The problem is with how libstdc++ moves the existing elements on reallocation.



More information about the Libstdc++ mailing list