1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 // <vector>
11 
12 // vector& operator=(vector&& c)
13 //     noexcept(
14 //          allocator_type::propagate_on_container_move_assignment::value &&
15 //          is_nothrow_move_assignable<allocator_type>::value);
16 
17 // This tests a conforming extension
18 
19 // UNSUPPORTED: c++98, c++03
20 
21 #include <vector>
22 #include <cassert>
23 
24 #include "test_macros.h"
25 #include "test_allocator.h"
26 
27 template <class T>
28 struct some_alloc
29 {
30     typedef T value_type;
31     some_alloc(const some_alloc&);
32 };
33 
34 template <class T>
35 struct some_alloc2
36 {
37     typedef T value_type;
38 
39     some_alloc2() {}
40     some_alloc2(const some_alloc2&);
41     void deallocate(void*, unsigned) {}
42 
43     typedef std::false_type propagate_on_container_move_assignment;
44     typedef std::true_type is_always_equal;
45 };
46 
47 template <class T>
48 struct some_alloc3
49 {
50     typedef T value_type;
51 
52     some_alloc3() {}
53     some_alloc3(const some_alloc3&);
54     void deallocate(void*, unsigned) {}
55 
56     typedef std::false_type propagate_on_container_move_assignment;
57     typedef std::false_type is_always_equal;
58 };
59 
60 int main()
61 {
62     {
63         typedef std::vector<bool> C;
64         LIBCPP_STATIC_ASSERT(std::is_nothrow_move_assignable<C>::value, "");
65     }
66     {
67         typedef std::vector<bool, test_allocator<bool>> C;
68         static_assert(!std::is_nothrow_move_assignable<C>::value, "");
69     }
70     {
71         typedef std::vector<bool, other_allocator<bool>> C;
72         LIBCPP_STATIC_ASSERT(std::is_nothrow_move_assignable<C>::value, "");
73     }
74     {
75         typedef std::vector<bool, some_alloc<bool>> C;
76 #if TEST_STD_VER > 14
77         LIBCPP_STATIC_ASSERT( std::is_nothrow_move_assignable<C>::value, "");
78 #else
79         static_assert(!std::is_nothrow_move_assignable<C>::value, "");
80 #endif
81     }
82 #if TEST_STD_VER > 14
83     {  // POCMA false, is_always_equal true
84         typedef std::vector<bool, some_alloc2<bool>> C;
85         LIBCPP_STATIC_ASSERT( std::is_nothrow_move_assignable<C>::value, "");
86     }
87     {  // POCMA false, is_always_equal false
88         typedef std::vector<bool, some_alloc3<bool>> C;
89         static_assert(!std::is_nothrow_move_assignable<C>::value, "");
90     }
91 #endif
92 }
93