[PowerPC][NFC] Cleanup PPCCTRLoopsVerify pass
[llvm-project.git] / libcxx / test / std / containers / sequences / list / list.special / swap_noexcept.pass.cpp
blobd378c3b662db39514a8c68a075acf2ca2ca402b1
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03
11 // <list>
13 // void swap(list& c)
14 // noexcept(!allocator_type::propagate_on_container_swap::value ||
15 // __is_nothrow_swappable<allocator_type>::value);
17 // In C++17, the standard says that swap shall have:
18 // noexcept(allocator_traits<Allocator>::is_always_equal::value);
20 // This tests a conforming extension
22 #include <list>
23 #include <utility>
24 #include <cassert>
26 #include "test_macros.h"
27 #include "MoveOnly.h"
28 #include "test_allocator.h"
30 template <class T>
31 struct some_alloc
33 typedef T value_type;
35 some_alloc() {}
36 some_alloc(const some_alloc&);
37 void deallocate(void*, unsigned) {}
39 typedef std::true_type propagate_on_container_swap;
42 template <class T>
43 struct some_alloc2
45 typedef T value_type;
47 some_alloc2() {}
48 some_alloc2(const some_alloc2&);
49 void deallocate(void*, unsigned) {}
51 typedef std::false_type propagate_on_container_swap;
52 typedef std::true_type is_always_equal;
55 int main(int, char**)
58 typedef std::list<MoveOnly> C;
59 static_assert(noexcept(swap(std::declval<C&>(), std::declval<C&>())), "");
61 #if defined(_LIBCPP_VERSION)
63 typedef std::list<MoveOnly, test_allocator<MoveOnly>> C;
64 static_assert(noexcept(swap(std::declval<C&>(), std::declval<C&>())), "");
67 typedef std::list<MoveOnly, other_allocator<MoveOnly>> C;
68 static_assert(noexcept(swap(std::declval<C&>(), std::declval<C&>())), "");
70 #endif // _LIBCPP_VERSION
72 typedef std::list<MoveOnly, some_alloc<MoveOnly>> C;
73 #if TEST_STD_VER >= 14
74 // In C++14, if POCS is set, swapping the allocator is required not to throw
75 static_assert( noexcept(swap(std::declval<C&>(), std::declval<C&>())), "");
76 #else
77 static_assert(!noexcept(swap(std::declval<C&>(), std::declval<C&>())), "");
78 #endif
80 #if TEST_STD_VER >= 14
82 typedef std::list<MoveOnly, some_alloc2<MoveOnly>> C;
83 // if the allocators are always equal, then the swap can be noexcept
84 static_assert( noexcept(swap(std::declval<C&>(), std::declval<C&>())), "");
86 #endif
89 return 0;