[libcxx-dev] Sequence container swap noexcept specifiers not-to-spec

Christopher Di Bella via libcxx-dev libcxx-dev at lists.llvm.org
Sat Feb 20 11:12:01 PST 2021


I've noticed that our sequence containers' noexcept specifiers for swap
aren't to spec. Is this intentional, or some gross oversight?

Example from <vector>

    void swap(vector&)
#if _LIBCPP_STD_VER >= 14
        _NOEXCEPT;
#else
        _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
                    __is_nothrow_swappable<allocator_type>::value);
#endif

To me, this looks like it's saying that swap is unconditionally noexcept in
C++17 and C++20, and possibly the opposite of [vector.capacity]/12
otherwise?

[vector.capacity]/12 <http://eel.is/c++draft/vector#capacity-12> notes:

constexpr void swap(vector& x)
  noexcept(allocator_traits<Allocator>::propagate_on_container_swap::value
||
           allocator_traits<Allocator>::is_always_equal::value);

If this is an oversight, I'll file a bug and patch ASAP. If it's
intentional, is it explicitly documented somewhere to explain the
deviation? This was a surprise when writing tests for std::ranges::swap's
noexcept status.

Cheers,

Chris

P.S. I've scoped this to sequence containers for now, but it might be all
allocator-aware containers.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/libcxx-dev/attachments/20210220/c25c5ede/attachment.html>


More information about the libcxx-dev mailing list