Failing test when run as C++11

Jonathan Wakely
Fri May 9 12:43:00 GMT 2014

On 09/05/14 14:30 +0200, Daniel Krügler wrote:
>2014-05-09 14:10 GMT+02:00 Jonathan Wakely <>:
>> Sorry, I didn't realise that PR needs authorisation.
>> It's basically the same code as the testcase saying it works
>> with GCC 4.5+ but not GCC 4.4, so you're not missing anything
>> interesting.
>If I understand (guessing somewhat on my side) the bug report and the
>corresponding test case correctly, it should ensure that in this
>scenario the template constructor is not used during the resize
>operation in this line:
>cbs[fd] = cb;
>nor during the default argument evaluation nor within the vector
>internals of the resize operation, right? (I'm not sure whether one of
>these aspects where considered more important than the other).

The unwanted calls to c::c<c>(c&) happen during vector::resize() when
copying/moving the pre-existing elements to the new storage (which is
why the vector size is chosen to go from 62 to 67, as that triggers a

>The least invasive one would be to (unconditionally) add the throw()
>to the copy constructor as you suggested, because this did not affect
>C++03 at all. But it seems to me that adding the conditional defaulted
>move constructor is more appropriate, because it points more clearly
>to the change of semantics during the language update.

My thoughts exactly. The empty throw() works in this specific case,
but isn't feasible for copy constructors in general. In the general
case, adding a nothrow move constructor would be the better fix.

An alternative viewpoint would be that during reallocation vector
should either try to move from rvalues (if that won't throw), or it
should ensure it copies from *const* lvalues (e.g. by using
const_cast).  That would need no changes to the testcase and would
avoid the change in behaviour from C++03 to C++11.  I'm not sure if
that's allowed by the standard (I think it is) or if that added safety
is really helpful for users.

More information about the Libstdc++ mailing list