move_assign_noexcept.pass.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. //===----------------------------------------------------------------------===//
  8. // <vector>
  9. // vector& operator=(vector&& c)
  10. // noexcept(
  11. // allocator_type::propagate_on_container_move_assignment::value &&
  12. // is_nothrow_move_assignable<allocator_type>::value);
  13. // This tests a conforming extension
  14. // UNSUPPORTED: c++98, c++03
  15. #include <vector>
  16. #include <cassert>
  17. #include "test_macros.h"
  18. #include "test_allocator.h"
  19. template <class T>
  20. struct some_alloc
  21. {
  22. typedef T value_type;
  23. some_alloc(const some_alloc&);
  24. };
  25. template <class T>
  26. struct some_alloc2
  27. {
  28. typedef T value_type;
  29. some_alloc2() {}
  30. some_alloc2(const some_alloc2&);
  31. void deallocate(void*, unsigned) {}
  32. typedef std::false_type propagate_on_container_move_assignment;
  33. typedef std::true_type is_always_equal;
  34. };
  35. template <class T>
  36. struct some_alloc3
  37. {
  38. typedef T value_type;
  39. some_alloc3() {}
  40. some_alloc3(const some_alloc3&);
  41. void deallocate(void*, unsigned) {}
  42. typedef std::false_type propagate_on_container_move_assignment;
  43. typedef std::false_type is_always_equal;
  44. };
  45. int main(int, char**)
  46. {
  47. #if defined(_LIBCPP_VERSION)
  48. {
  49. typedef std::vector<bool> C;
  50. static_assert(std::is_nothrow_move_assignable<C>::value, "");
  51. }
  52. #endif // _LIBCPP_VERSION
  53. {
  54. typedef std::vector<bool, test_allocator<bool>> C;
  55. static_assert(!std::is_nothrow_move_assignable<C>::value, "");
  56. }
  57. #if defined(_LIBCPP_VERSION)
  58. {
  59. typedef std::vector<bool, other_allocator<bool>> C;
  60. static_assert(std::is_nothrow_move_assignable<C>::value, "");
  61. }
  62. #endif // _LIBCPP_VERSION
  63. {
  64. #if TEST_STD_VER > 14
  65. #if defined(_LIBCPP_VERSION)
  66. typedef std::vector<bool, some_alloc<bool>> C;
  67. static_assert( std::is_nothrow_move_assignable<C>::value, "");
  68. #endif // _LIBCPP_VERSION
  69. #else
  70. typedef std::vector<bool, some_alloc<bool>> C;
  71. static_assert(!std::is_nothrow_move_assignable<C>::value, "");
  72. #endif
  73. }
  74. #if TEST_STD_VER > 14
  75. #if defined(_LIBCPP_VERSION)
  76. { // POCMA false, is_always_equal true
  77. typedef std::vector<bool, some_alloc2<bool>> C;
  78. static_assert( std::is_nothrow_move_assignable<C>::value, "");
  79. }
  80. #endif // _LIBCPP_VERSION
  81. { // POCMA false, is_always_equal false
  82. typedef std::vector<bool, some_alloc3<bool>> C;
  83. static_assert(!std::is_nothrow_move_assignable<C>::value, "");
  84. }
  85. #endif
  86. return 0;
  87. }