move_assign_noexcept.pass.cpp (2554B)
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 "MoveOnly.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 61 int main() 62 { 63 { 64 typedef std::vector<MoveOnly> C; 65 static_assert(std::is_nothrow_move_assignable<C>::value, ""); 66 } 67 { 68 typedef std::vector<MoveOnly, test_allocator<MoveOnly>> C; 69 static_assert(!std::is_nothrow_move_assignable<C>::value, ""); 70 } 71 { 72 typedef std::vector<MoveOnly, other_allocator<MoveOnly>> C; 73 static_assert(std::is_nothrow_move_assignable<C>::value, ""); 74 } 75 { 76 typedef std::vector<MoveOnly, some_alloc<MoveOnly>> C; 77 // In C++17, move assignment for allocators are not allowed to throw 78 #if TEST_STD_VER > 14 79 static_assert( std::is_nothrow_move_assignable<C>::value, ""); 80 #else 81 static_assert(!std::is_nothrow_move_assignable<C>::value, ""); 82 #endif 83 } 84 85 #if TEST_STD_VER > 14 86 { // POCMA false, is_always_equal true 87 typedef std::vector<MoveOnly, some_alloc2<MoveOnly>> C; 88 static_assert( std::is_nothrow_move_assignable<C>::value, ""); 89 } 90 { // POCMA false, is_always_equal false 91 typedef std::vector<MoveOnly, some_alloc3<MoveOnly>> C; 92 static_assert(!std::is_nothrow_move_assignable<C>::value, ""); 93 } 94 #endif 95 }