move_noexcept.pass.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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(vector&&)
  10. // noexcept(is_nothrow_move_constructible<allocator_type>::value);
  11. // This tests a conforming extension
  12. // UNSUPPORTED: c++98, c++03
  13. #include <vector>
  14. #include <cassert>
  15. #include "test_macros.h"
  16. #include "test_allocator.h"
  17. template <class T>
  18. struct some_alloc
  19. {
  20. typedef T value_type;
  21. some_alloc(const some_alloc&);
  22. };
  23. int main(int, char**)
  24. {
  25. #if defined(_LIBCPP_VERSION)
  26. {
  27. typedef std::vector<bool> C;
  28. static_assert(std::is_nothrow_move_constructible<C>::value, "");
  29. }
  30. {
  31. typedef std::vector<bool, test_allocator<bool>> C;
  32. static_assert(std::is_nothrow_move_constructible<C>::value, "");
  33. }
  34. {
  35. typedef std::vector<bool, other_allocator<bool>> C;
  36. static_assert(std::is_nothrow_move_constructible<C>::value, "");
  37. }
  38. #endif // _LIBCPP_VERSION
  39. {
  40. // In C++17, move constructors for allocators are not allowed to throw
  41. #if TEST_STD_VER > 14
  42. #if defined(_LIBCPP_VERSION)
  43. typedef std::vector<bool, some_alloc<bool>> C;
  44. static_assert( std::is_nothrow_move_constructible<C>::value, "");
  45. #endif // _LIBCPP_VERSION
  46. #else
  47. typedef std::vector<bool, some_alloc<bool>> C;
  48. static_assert(!std::is_nothrow_move_constructible<C>::value, "");
  49. #endif
  50. }
  51. return 0;
  52. }