[v3 patch] Use std::__is_nothrow_swappable in __alloc_traits::_S_nothrow_swap()

Jonathan Wakely jwakely@redhat.com
Wed Jun 17 10:51:00 GMT 2015


This fixes a bug in _S_nothrow_swap(), where I assumed that allocator
types are always swappable, but they don't need to be if
propagate_on_container_swap is false. Thanks to Ville's new trait it's
easy to fix.

For the branches we don't have __is_nothrow_swappable, but could
dispatch on the propagation trait so we only test if swapping throws
when we're actually going to swap. However, I'm not sure if
_S_nothrow_swap() is actually worth keeping, because the standard says
that for allocators that propagate on swap, they shall be swappable
and swapping them shall not throw exceptions.

This means the current code is doubly-wrong, it assumes allocators are
always swappable (not required to be true) and then tests whether
swapping them will throw (if they're swappable swapping must not
throw).

So we could remove all uses of _Alloc_traits::_S_nothrow_swap() and
make containers' swap() members unconditionally noexcept. The only
reason to keep _S_nothrow_swap is if we want to support allocators
with throwing swaps as an extension.  Thoughts?

For now I'm committing this to trunk, tested powerpc64le-linux.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: patch.txt
Type: text/x-patch
Size: 781 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20150617/246e0672/attachment.bin>


More information about the Libstdc++ mailing list