xref: /llvm-project/libcxx/test/std/containers/sequences/vector.bool/move_assign_noexcept.pass.cpp (revision 31cbe0f240f660f15602c96b787c58a26f17e179)
15a83710eSEric Fiselier //===----------------------------------------------------------------------===//
25a83710eSEric Fiselier //
357b08b09SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
457b08b09SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
557b08b09SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
65a83710eSEric Fiselier //
75a83710eSEric Fiselier //===----------------------------------------------------------------------===//
85a83710eSEric Fiselier 
95a83710eSEric Fiselier // <vector>
105a83710eSEric Fiselier 
115a83710eSEric Fiselier // vector& operator=(vector&& c)
125a83710eSEric Fiselier //     noexcept(
135a83710eSEric Fiselier //          allocator_type::propagate_on_container_move_assignment::value &&
145a83710eSEric Fiselier //          is_nothrow_move_assignable<allocator_type>::value);
155a83710eSEric Fiselier 
165a83710eSEric Fiselier // This tests a conforming extension
175a83710eSEric Fiselier 
18*31cbe0f2SLouis Dionne // UNSUPPORTED: c++03
19f2f2a639SEric Fiselier 
205a83710eSEric Fiselier #include <vector>
215a83710eSEric Fiselier #include <cassert>
225a83710eSEric Fiselier 
23249b03efSEric Fiselier #include "test_macros.h"
245a83710eSEric Fiselier #include "test_allocator.h"
255a83710eSEric Fiselier 
265a83710eSEric Fiselier template <class T>
275a83710eSEric Fiselier struct some_alloc
285a83710eSEric Fiselier {
295a83710eSEric Fiselier     typedef T value_type;
305a83710eSEric Fiselier     some_alloc(const some_alloc&);
315a83710eSEric Fiselier };
325a83710eSEric Fiselier 
331378a5aeSMarshall Clow template <class T>
341378a5aeSMarshall Clow struct some_alloc2
351378a5aeSMarshall Clow {
361378a5aeSMarshall Clow     typedef T value_type;
371378a5aeSMarshall Clow 
some_alloc2some_alloc2381378a5aeSMarshall Clow     some_alloc2() {}
391378a5aeSMarshall Clow     some_alloc2(const some_alloc2&);
deallocatesome_alloc2401378a5aeSMarshall Clow     void deallocate(void*, unsigned) {}
411378a5aeSMarshall Clow 
421378a5aeSMarshall Clow     typedef std::false_type propagate_on_container_move_assignment;
431378a5aeSMarshall Clow     typedef std::true_type is_always_equal;
441378a5aeSMarshall Clow };
451378a5aeSMarshall Clow 
461378a5aeSMarshall Clow template <class T>
471378a5aeSMarshall Clow struct some_alloc3
481378a5aeSMarshall Clow {
491378a5aeSMarshall Clow     typedef T value_type;
501378a5aeSMarshall Clow 
some_alloc3some_alloc3511378a5aeSMarshall Clow     some_alloc3() {}
521378a5aeSMarshall Clow     some_alloc3(const some_alloc3&);
deallocatesome_alloc3531378a5aeSMarshall Clow     void deallocate(void*, unsigned) {}
541378a5aeSMarshall Clow 
551378a5aeSMarshall Clow     typedef std::false_type propagate_on_container_move_assignment;
561378a5aeSMarshall Clow     typedef std::false_type is_always_equal;
571378a5aeSMarshall Clow };
581378a5aeSMarshall Clow 
main(int,char **)592df59c50SJF Bastien int main(int, char**)
605a83710eSEric Fiselier {
6103fe6e2dSStephan T. Lavavej #if defined(_LIBCPP_VERSION)
625a83710eSEric Fiselier     {
635a83710eSEric Fiselier         typedef std::vector<bool> C;
6403fe6e2dSStephan T. Lavavej         static_assert(std::is_nothrow_move_assignable<C>::value, "");
655a83710eSEric Fiselier     }
6603fe6e2dSStephan T. Lavavej #endif // _LIBCPP_VERSION
675a83710eSEric Fiselier     {
685a83710eSEric Fiselier         typedef std::vector<bool, test_allocator<bool>> C;
695a83710eSEric Fiselier         static_assert(!std::is_nothrow_move_assignable<C>::value, "");
705a83710eSEric Fiselier     }
7103fe6e2dSStephan T. Lavavej #if defined(_LIBCPP_VERSION)
725a83710eSEric Fiselier     {
735a83710eSEric Fiselier         typedef std::vector<bool, other_allocator<bool>> C;
7403fe6e2dSStephan T. Lavavej         static_assert(std::is_nothrow_move_assignable<C>::value, "");
755a83710eSEric Fiselier     }
7603fe6e2dSStephan T. Lavavej #endif // _LIBCPP_VERSION
775a83710eSEric Fiselier     {
781378a5aeSMarshall Clow #if TEST_STD_VER > 14
7903fe6e2dSStephan T. Lavavej #if defined(_LIBCPP_VERSION)
8003fe6e2dSStephan T. Lavavej         typedef std::vector<bool, some_alloc<bool>> C;
8103fe6e2dSStephan T. Lavavej         static_assert( std::is_nothrow_move_assignable<C>::value, "");
8203fe6e2dSStephan T. Lavavej #endif // _LIBCPP_VERSION
831378a5aeSMarshall Clow #else
8403fe6e2dSStephan T. Lavavej         typedef std::vector<bool, some_alloc<bool>> C;
851378a5aeSMarshall Clow         static_assert(!std::is_nothrow_move_assignable<C>::value, "");
861378a5aeSMarshall Clow #endif
871378a5aeSMarshall Clow     }
881378a5aeSMarshall Clow #if TEST_STD_VER > 14
8903fe6e2dSStephan T. Lavavej #if defined(_LIBCPP_VERSION)
901378a5aeSMarshall Clow     {  // POCMA false, is_always_equal true
911378a5aeSMarshall Clow         typedef std::vector<bool, some_alloc2<bool>> C;
9203fe6e2dSStephan T. Lavavej         static_assert( std::is_nothrow_move_assignable<C>::value, "");
931378a5aeSMarshall Clow     }
9403fe6e2dSStephan T. Lavavej #endif // _LIBCPP_VERSION
951378a5aeSMarshall Clow     {  // POCMA false, is_always_equal false
961378a5aeSMarshall Clow         typedef std::vector<bool, some_alloc3<bool>> C;
975a83710eSEric Fiselier         static_assert(!std::is_nothrow_move_assignable<C>::value, "");
985a83710eSEric Fiselier     }
995a83710eSEric Fiselier #endif
1002df59c50SJF Bastien 
1012df59c50SJF Bastien   return 0;
1025a83710eSEric Fiselier }
103