[PATCH] D21820: [libcxx] [test] Make swap_noexcept.pass.cpp tests more portable.

Stephan T. Lavavej via cfe-commits cfe-commits at lists.llvm.org
Tue Jun 28 16:10:08 PDT 2016


STL_MSFT created this revision.
STL_MSFT added reviewers: EricWF, mclow.lists.
STL_MSFT added a subscriber: cfe-commits.

Make swap_noexcept.pass.cpp tests more portable.

These tests define types like some_alloc, which dramatically fail to meet the allocator requirements. They don't even have allocate() member functions. Then, they actually default-construct containers with these not-allocators. MSVC's STL can't tolerate this, because we need to dynamically allocate sentinel nodes and debugging machinery.

A true fix would involve centralizing these allocators, allowing POCS/is_always_equal/etc. to be customized as desired, while actually providing conformant allocators. But in the meantime, I have incremental improvements.

The bulk of these changes involves including <utility> for declval(), then replacing

C c1, c2;
static_assert(noexcept(swap(c1, c2)), "");

with

static_assert(noexcept(swap(std::declval<C&>(), std::declval<C&>())), "");

This avoids instantiating the containers' default constructors.

The other part of these changes involves replacing static_assert with LIBCPP_STATIC_ASSERT for certain things that aren't guaranteed by the Standard. (We're already including "test_macros.h" explicitly.)


test/std/containers/associative/map/map.special/swap_noexcept.pass.cpp
test/std/containers/associative/multimap/multimap.special/swap_noexcept.pass.cpp
test/std/containers/associative/multiset/multiset.special/swap_noexcept.pass.cpp
test/std/containers/associative/set/set.special/swap_noexcept.pass.cpp

For the ordered associative containers, the Working Paper inspects is_always_equal && is_nothrow_swappable_v<Compare>.

The updated lines are using std::less or some_comp2, which are nothrow-swappable, so that's okay. However, they're using test_allocator (stateful), other_allocator (stateful), or some_alloc3 (with is_always_equal being false_type). Therefore, these assertions aren't guaranteed by the WP.

BONUS CHANGE: In multimap.special/swap_noexcept.pass.cpp, there was one occurrence of std::map that's being changed to std::multimap.


test/std/containers/unord/unord.map/unord.map.swap/swap_noexcept.pass.cpp
test/std/containers/unord/unord.multimap/unord.multimap.swap/swap_noexcept.pass.cpp
test/std/containers/unord/unord.multiset/unord.multiset.swap/swap_noexcept.pass.cpp
test/std/containers/unord/unord.set/unord.set.swap/swap_noexcept.pass.cpp

Same for the unordered associative containers. They inspect is_always_equal && is_nothrow_swappable_v<Hash> && is_nothrow_swappable_v<Pred>. std::hash/std::equal_to and some_hash2/some_comp2 are nothrow-swappable, but test_allocator/other_allocator/some_alloc3 aren't always-equal.


test/std/containers/sequences/deque/deque.special/swap_noexcept.pass.cpp
test/std/containers/sequences/forwardlist/forwardlist.spec/swap_noexcept.pass.cpp
test/std/containers/sequences/list/list.special/swap_noexcept.pass.cpp

For these sequences, the WP inspects is_always_equal. test_allocator/other_allocator aren't always-equal.


test/std/containers/sequences/vector/vector.special/swap_noexcept.pass.cpp
test/std/strings/basic.string/string.nonmembers/string.special/swap_noexcept.pass.cpp

For vector and basic_string, the WP inspects POCS || is_always_equal. test_allocator is stateful and doesn't set POCS, which defaults to false.


test/std/containers/container.adaptors/priority.queue/priqueue.special/swap_noexcept.pass.cpp
test/std/containers/container.adaptors/queue/queue.special/swap_noexcept.pass.cpp
test/std/containers/container.adaptors/stack/stack.special/swap_noexcept.pass.cpp

No LIBCPP_STATIC_ASSERT changes, just declval.


test/std/containers/sequences/vector.bool/swap_noexcept.pass.cpp

vector<bool>::swap() is depicted without noexcept in the WP.

http://reviews.llvm.org/D21820

Files:
  test/std/containers/associative/map/map.special/swap_noexcept.pass.cpp
  test/std/containers/associative/multimap/multimap.special/swap_noexcept.pass.cpp
  test/std/containers/associative/multiset/multiset.special/swap_noexcept.pass.cpp
  test/std/containers/associative/set/set.special/swap_noexcept.pass.cpp
  test/std/containers/container.adaptors/priority.queue/priqueue.special/swap_noexcept.pass.cpp
  test/std/containers/container.adaptors/queue/queue.special/swap_noexcept.pass.cpp
  test/std/containers/container.adaptors/stack/stack.special/swap_noexcept.pass.cpp
  test/std/containers/sequences/deque/deque.special/swap_noexcept.pass.cpp
  test/std/containers/sequences/forwardlist/forwardlist.spec/swap_noexcept.pass.cpp
  test/std/containers/sequences/list/list.special/swap_noexcept.pass.cpp
  test/std/containers/sequences/vector.bool/swap_noexcept.pass.cpp
  test/std/containers/sequences/vector/vector.special/swap_noexcept.pass.cpp
  test/std/containers/unord/unord.map/unord.map.swap/swap_noexcept.pass.cpp
  test/std/containers/unord/unord.multimap/unord.multimap.swap/swap_noexcept.pass.cpp
  test/std/containers/unord/unord.multiset/unord.multiset.swap/swap_noexcept.pass.cpp
  test/std/containers/unord/unord.set/unord.set.swap/swap_noexcept.pass.cpp
  test/std/strings/basic.string/string.nonmembers/string.special/swap_noexcept.pass.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D21820.62147.patch
Type: text/x-patch
Size: 46666 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160628/5070a409/attachment-0001.bin>


More information about the cfe-commits mailing list