This is an archive of the discontinued LLVM Phabricator instance.

[libcxx] [test] Make swap_noexcept.pass.cpp tests more portable.
ClosedPublic

Authored by STL_MSFT on Jun 28 2016, 4:10 PM.

Details

Summary

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.

Diff Detail

Event Timeline

STL_MSFT updated this revision to Diff 62147.Jun 28 2016, 4:10 PM
STL_MSFT retitled this revision from to [libcxx] [test] Make swap_noexcept.pass.cpp tests more portable..
STL_MSFT updated this object.
STL_MSFT added reviewers: EricWF, mclow.lists.
STL_MSFT added a subscriber: cfe-commits.
EricWF accepted this revision.Jul 24 2016, 5:21 PM
EricWF edited edge metadata.

I'm not thrilled with this, but as you mentioned actually fixing this will be a lot of work. I opened a bug to track that work https://llvm.org/bugs/show_bug.cgi?id=28687.
However for now this patch LGTM.

This revision is now accepted and ready to land.Jul 24 2016, 5:21 PM
EricWF closed this revision.Jul 24 2016, 5:23 PM

r276590.