1 //===----------------------------------------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // UNSUPPORTED: c++98, c++03
15 // noexcept(!allocator_type::propagate_on_container_swap::value ||
16 // __is_nothrow_swappable<allocator_type>::value);
18 // In C++17, the standard says that swap shall have:
19 // noexcept(allocator_traits<Allocator>::is_always_equal::value);
21 // This tests a conforming extension
27 #include "test_macros.h"
29 #include "test_allocator.h"
37 some_alloc(const some_alloc&);
38 void deallocate(void*, unsigned) {}
40 typedef std::true_type propagate_on_container_swap;
49 some_alloc2(const some_alloc2&);
50 void deallocate(void*, unsigned) {}
52 typedef std::false_type propagate_on_container_swap;
53 typedef std::true_type is_always_equal;
59 typedef std::list<MoveOnly> C;
60 static_assert(noexcept(swap(std::declval<C&>(), std::declval<C&>())), "");
63 typedef std::list<MoveOnly, test_allocator<MoveOnly>> C;
64 LIBCPP_STATIC_ASSERT(noexcept(swap(std::declval<C&>(), std::declval<C&>())), "");
67 typedef std::list<MoveOnly, other_allocator<MoveOnly>> C;
68 LIBCPP_STATIC_ASSERT(noexcept(swap(std::declval<C&>(), std::declval<C&>())), "");
71 typedef std::list<MoveOnly, some_alloc<MoveOnly>> C;
72 #if TEST_STD_VER >= 14
73 // In c++14, if POCS is set, swapping the allocator is required not to throw
74 static_assert( noexcept(swap(std::declval<C&>(), std::declval<C&>())), "");
76 static_assert(!noexcept(swap(std::declval<C&>(), std::declval<C&>())), "");
79 #if TEST_STD_VER >= 14
81 typedef std::list<MoveOnly, some_alloc2<MoveOnly>> C;
82 // if the allocators are always equal, then the swap can be noexcept
83 static_assert( noexcept(swap(std::declval<C&>(), std::declval<C&>())), "");