[libc++] Enable move semantics for vector in C++03
authorNikolas Klauser <nikolasklauser@berlin.de>
Thu, 19 May 2022 10:46:09 +0000 (12:46 +0200)
committerNikolas Klauser <nikolasklauser@berlin.de>
Thu, 19 May 2022 14:11:56 +0000 (16:11 +0200)
We require move semantics in C++03 anyways, so let's enable them for the containers.

Reviewed By: ldionne, #libc

Spies: libcxx-commits

Differential Revision: https://reviews.llvm.org/D123802

20 files changed:
libcxx/include/__iterator/move_iterator.h
libcxx/include/__utility/move.h
libcxx/include/vector
libcxx/test/std/containers/sequences/array/array.creation/to_array.fail.cpp
libcxx/test/std/containers/sequences/vector/vector.cons/assign_move.pass.cpp
libcxx/test/std/containers/sequences/vector/vector.cons/copy.move_only.verify.cpp
libcxx/test/std/containers/sequences/vector/vector.cons/move.addressof.compile.pass.cpp
libcxx/test/std/containers/sequences/vector/vector.cons/move.pass.cpp
libcxx/test/std/containers/sequences/vector/vector.cons/move_alloc.pass.cpp
libcxx/test/std/containers/sequences/vector/vector.modifiers/emplace.addressof.compile.pass.cpp
libcxx/test/std/containers/sequences/vector/vector.modifiers/emplace.pass.cpp
libcxx/test/std/containers/sequences/vector/vector.modifiers/emplace_back.pass.cpp
libcxx/test/std/containers/sequences/vector/vector.modifiers/insert_iter_rvalue.addressof.compile.pass.cpp
libcxx/test/std/containers/sequences/vector/vector.modifiers/insert_iter_rvalue.pass.cpp
libcxx/test/std/containers/sequences/vector/vector.modifiers/push_back_rvalue.pass.cpp
libcxx/test/std/containers/sequences/vector/vector.modifiers/resize_not_move_insertable.fail.cpp
libcxx/test/std/iterators/predef.iterators/move.iterators/move.iterator/types.pass.cpp
libcxx/test/std/utilities/utility/forward/move_if_noexcept.pass.cpp
libcxx/test/support/MoveOnly.h
libcxx/test/support/test_allocator.h

index b40e650..5beb831 100644 (file)
@@ -79,17 +79,12 @@ public:
     typedef typename iterator_traits<iterator_type>::difference_type difference_type;
     typedef iterator_type pointer;
 
-#ifndef _LIBCPP_CXX03_LANG
     typedef typename iterator_traits<iterator_type>::reference __reference;
     typedef typename conditional<
             is_reference<__reference>::value,
             typename remove_reference<__reference>::type&&,
             __reference
         >::type reference;
-#else
-    typedef typename iterator_traits<iterator_type>::reference reference;
-#endif
-
 #endif // _LIBCPP_STD_VER > 17
 
 #if _LIBCPP_STD_VER > 17
index 7d1c8c2..da0d986 100644 (file)
@@ -26,15 +26,10 @@ move(_Tp&& __t) _NOEXCEPT {
   return static_cast<_Up&&>(__t);
 }
 
-#ifndef _LIBCPP_CXX03_LANG
 template <class _Tp>
 using __move_if_noexcept_result_t =
     typename conditional<!is_nothrow_move_constructible<_Tp>::value && is_copy_constructible<_Tp>::value, const _Tp&,
                          _Tp&&>::type;
-#else // _LIBCPP_CXX03_LANG
-template <class _Tp>
-using __move_if_noexcept_result_t = const _Tp&;
-#endif
 
 template <class _Tp>
 _LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 __move_if_noexcept_result_t<_Tp>
index 07c7476..5238ac5 100644 (file)
@@ -435,9 +435,14 @@ public:
     vector(initializer_list<value_type> __il, const allocator_type& __a);
 
     _LIBCPP_INLINE_VISIBILITY
+    vector& operator=(initializer_list<value_type> __il)
+        {assign(__il.begin(), __il.end()); return *this;}
+#endif // !_LIBCPP_CXX03_LANG
+
+    _LIBCPP_INLINE_VISIBILITY
     vector(vector&& __x)
 #if _LIBCPP_STD_VER > 14
-        _NOEXCEPT;
+        noexcept;
 #else
         _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
 #endif
@@ -448,12 +453,6 @@ public:
     vector& operator=(vector&& __x)
         _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value));
 
-    _LIBCPP_INLINE_VISIBILITY
-    vector& operator=(initializer_list<value_type> __il)
-        {assign(__il.begin(), __il.end()); return *this;}
-
-#endif // !_LIBCPP_CXX03_LANG
-
     template <class _InputIterator>
         typename enable_if
         <
@@ -565,41 +564,26 @@ public:
     const value_type* data() const _NOEXCEPT
         {return _VSTD::__to_address(this->__begin_);}
 
-#ifdef _LIBCPP_CXX03_LANG
-    _LIBCPP_INLINE_VISIBILITY
-    void __emplace_back(const value_type& __x) { push_back(__x); }
-#else
-    template <class _Arg>
-    _LIBCPP_INLINE_VISIBILITY
-    void __emplace_back(_Arg&& __arg) {
-      emplace_back(_VSTD::forward<_Arg>(__arg));
-    }
-#endif
-
     _LIBCPP_INLINE_VISIBILITY void push_back(const_reference __x);
 
-#ifndef _LIBCPP_CXX03_LANG
     _LIBCPP_INLINE_VISIBILITY void push_back(value_type&& __x);
 
     template <class... _Args>
-        _LIBCPP_INLINE_VISIBILITY
+    _LIBCPP_INLINE_VISIBILITY
 #if _LIBCPP_STD_VER > 14
         reference emplace_back(_Args&&... __args);
 #else
         void      emplace_back(_Args&&... __args);
 #endif
-#endif // !_LIBCPP_CXX03_LANG
 
     _LIBCPP_INLINE_VISIBILITY
     void pop_back();
 
     iterator insert(const_iterator __position, const_reference __x);
 
-#ifndef _LIBCPP_CXX03_LANG
     iterator insert(const_iterator __position, value_type&& __x);
     template <class... _Args>
-        iterator emplace(const_iterator __position, _Args&&... __args);
-#endif // !_LIBCPP_CXX03_LANG
+    iterator emplace(const_iterator __position, _Args&&... __args);
 
     iterator insert(const_iterator __position, size_type __n, const_reference __x);
     template <class _InputIterator>
@@ -724,7 +708,6 @@ private:
         __annotate_shrink(__old_size);
     }
 
-#ifndef _LIBCPP_CXX03_LANG
     template <class _Up>
     _LIBCPP_INLINE_VISIBILITY
     inline void __push_back_slow_path(_Up&& __x);
@@ -732,11 +715,6 @@ private:
     template <class... _Args>
     _LIBCPP_INLINE_VISIBILITY
     inline void __emplace_back_slow_path(_Args&&... __args);
-#else
-    template <class _Up>
-    _LIBCPP_INLINE_VISIBILITY
-    inline void __push_back_slow_path(_Up& __x);
-#endif
 
     // The following functions are no-ops outside of AddressSanitizer mode.
     // We call annotatations only for the default Allocator because other allocators
@@ -1110,7 +1088,7 @@ vector<_Tp, _Allocator>::vector(_InputIterator __first,
 {
     _VSTD::__debug_db_insert_c(this);
     for (; __first != __last; ++__first)
-        __emplace_back(*__first);
+        emplace_back(*__first);
 }
 
 template <class _Tp, class _Allocator>
@@ -1125,7 +1103,7 @@ vector<_Tp, _Allocator>::vector(_InputIterator __first, _InputIterator __last, c
 {
     _VSTD::__debug_db_insert_c(this);
     for (; __first != __last; ++__first)
-        __emplace_back(*__first);
+        emplace_back(*__first);
 }
 
 template <class _Tp, class _Allocator>
@@ -1190,13 +1168,11 @@ vector<_Tp, _Allocator>::vector(const vector& __x, const __type_identity_t<alloc
     }
 }
 
-#ifndef _LIBCPP_CXX03_LANG
-
 template <class _Tp, class _Allocator>
 inline _LIBCPP_INLINE_VISIBILITY
 vector<_Tp, _Allocator>::vector(vector&& __x)
 #if _LIBCPP_STD_VER > 14
-        _NOEXCEPT
+        noexcept
 #else
         _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
 #endif
@@ -1231,6 +1207,8 @@ vector<_Tp, _Allocator>::vector(vector&& __x, const __type_identity_t<allocator_
     }
 }
 
+#ifndef _LIBCPP_CXX03_LANG
+
 template <class _Tp, class _Allocator>
 inline _LIBCPP_INLINE_VISIBILITY
 vector<_Tp, _Allocator>::vector(initializer_list<value_type> __il)
@@ -1256,6 +1234,8 @@ vector<_Tp, _Allocator>::vector(initializer_list<value_type> __il, const allocat
     }
 }
 
+#endif // _LIBCPP_CXX03_LANG
+
 template <class _Tp, class _Allocator>
 inline _LIBCPP_INLINE_VISIBILITY
 vector<_Tp, _Allocator>&
@@ -1295,8 +1275,6 @@ vector<_Tp, _Allocator>::__move_assign(vector& __c, true_type)
     std::__debug_db_swap(this, std::addressof(__c));
 }
 
-#endif // !_LIBCPP_CXX03_LANG
-
 template <class _Tp, class _Allocator>
 inline _LIBCPP_INLINE_VISIBILITY
 vector<_Tp, _Allocator>&
@@ -1325,7 +1303,7 @@ vector<_Tp, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
 {
     clear();
     for (; __first != __last; ++__first)
-        __emplace_back(*__first);
+        emplace_back(*__first);
 }
 
 template <class _Tp, class _Allocator>
@@ -1519,11 +1497,7 @@ vector<_Tp, _Allocator>::shrink_to_fit() _NOEXCEPT
 template <class _Tp, class _Allocator>
 template <class _Up>
 void
-#ifndef _LIBCPP_CXX03_LANG
 vector<_Tp, _Allocator>::__push_back_slow_path(_Up&& __x)
-#else
-vector<_Tp, _Allocator>::__push_back_slow_path(_Up& __x)
-#endif
 {
     allocator_type& __a = this->__alloc();
     __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), size(), __a);
@@ -1546,8 +1520,6 @@ vector<_Tp, _Allocator>::push_back(const_reference __x)
         __push_back_slow_path(__x);
 }
 
-#ifndef _LIBCPP_CXX03_LANG
-
 template <class _Tp, class _Allocator>
 inline _LIBCPP_INLINE_VISIBILITY
 void
@@ -1595,8 +1567,6 @@ vector<_Tp, _Allocator>::emplace_back(_Args&&... __args)
 #endif
 }
 
-#endif // !_LIBCPP_CXX03_LANG
-
 template <class _Tp, class _Allocator>
 inline
 void
@@ -1693,8 +1663,6 @@ vector<_Tp, _Allocator>::insert(const_iterator __position, const_reference __x)
     return __make_iter(__p);
 }
 
-#ifndef _LIBCPP_CXX03_LANG
-
 template <class _Tp, class _Allocator>
 typename vector<_Tp, _Allocator>::iterator
 vector<_Tp, _Allocator>::insert(const_iterator __position, value_type&& __x)
@@ -1755,8 +1723,6 @@ vector<_Tp, _Allocator>::emplace(const_iterator __position, _Args&&... __args)
     return __make_iter(__p);
 }
 
-#endif // !_LIBCPP_CXX03_LANG
-
 template <class _Tp, class _Allocator>
 typename vector<_Tp, _Allocator>::iterator
 vector<_Tp, _Allocator>::insert(const_iterator __position, size_type __n, const_reference __x)
@@ -2126,9 +2092,15 @@ public:
     vector(initializer_list<value_type> __il, const allocator_type& __a);
 
     _LIBCPP_INLINE_VISIBILITY
+    vector& operator=(initializer_list<value_type> __il)
+        {assign(__il.begin(), __il.end()); return *this;}
+
+#endif // !_LIBCPP_CXX03_LANG
+
+    _LIBCPP_INLINE_VISIBILITY
     vector(vector&& __v)
 #if _LIBCPP_STD_VER > 14
-        _NOEXCEPT;
+        noexcept;
 #else
         _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
 #endif
@@ -2137,12 +2109,6 @@ public:
     vector& operator=(vector&& __v)
         _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value));
 
-    _LIBCPP_INLINE_VISIBILITY
-    vector& operator=(initializer_list<value_type> __il)
-        {assign(__il.begin(), __il.end()); return *this;}
-
-#endif // !_LIBCPP_CXX03_LANG
-
     template <class _InputIterator>
         typename enable_if
         <
@@ -2739,8 +2705,6 @@ vector<bool, _Allocator>::operator=(const vector& __v)
     return *this;
 }
 
-#ifndef _LIBCPP_CXX03_LANG
-
 template <class _Allocator>
 inline _LIBCPP_INLINE_VISIBILITY vector<bool, _Allocator>::vector(vector&& __v)
 #if _LIBCPP_STD_VER > 14
@@ -2812,8 +2776,6 @@ vector<bool, _Allocator>::__move_assign(vector& __c, true_type)
     __c.__cap() = __c.__size_ = 0;
 }
 
-#endif // !_LIBCPP_CXX03_LANG
-
 template <class _Allocator>
 void
 vector<bool, _Allocator>::assign(size_type __n, const value_type& __x)
index 4961fe5..9e7b456 100644 (file)
@@ -28,14 +28,14 @@ int main(int, char**) {
   {
     MoveOnly mo[] = {MoveOnly{3}};
     // expected-error@array:* {{to_array requires copy constructible elements}}
-    // expected-error@array:* {{call to implicitly-deleted copy constructor of 'MoveOnly'}}
+    // expected-error-re@array:* {{{{(call to implicitly-deleted copy constructor of 'MoveOnly')|(call to deleted constructor of 'MoveOnly')}}}}
     std::to_array(mo); // expected-note {{requested here}}
   }
 
   {
     const MoveOnly cmo[] = {MoveOnly{3}};
     // expected-error@array:* {{to_array requires move constructible elements}}
-    // expected-error@array:* {{call to implicitly-deleted copy constructor of 'MoveOnly'}}
+    // expected-error-re@array:* {{{{(call to implicitly-deleted copy constructor of 'MoveOnly')|(call to deleted constructor of 'MoveOnly')}}}}
     std::to_array(std::move(cmo)); // expected-note {{requested here}}
   }
 
index 4d81380..3e25dc9 100644 (file)
@@ -6,7 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 
-// UNSUPPORTED: c++03
+// UNSUPPORTED: c++03 && !stdlib=libc++
 
 // <vector>
 
@@ -78,8 +78,8 @@ int main(int, char**)
         assert(is_contiguous_container_asan_correct(l2));
     }
     {
-        std::vector<MoveOnly, min_allocator<MoveOnly> > l(min_allocator<MoveOnly>{});
-        std::vector<MoveOnly, min_allocator<MoveOnly> > lo(min_allocator<MoveOnly>{});
+        std::vector<MoveOnly, min_allocator<MoveOnly> > l((min_allocator<MoveOnly>()));
+        std::vector<MoveOnly, min_allocator<MoveOnly> > lo((min_allocator<MoveOnly>()));
         assert(is_contiguous_container_asan_correct(l));
         assert(is_contiguous_container_asan_correct(lo));
         for (int i = 1; i <= 3; ++i)
@@ -89,7 +89,7 @@ int main(int, char**)
         }
         assert(is_contiguous_container_asan_correct(l));
         assert(is_contiguous_container_asan_correct(lo));
-        std::vector<MoveOnly, min_allocator<MoveOnly> > l2(min_allocator<MoveOnly>{});
+        std::vector<MoveOnly, min_allocator<MoveOnly> > l2((min_allocator<MoveOnly>()));
         l2 = std::move(l);
         assert(l2 == lo);
         assert(l.empty());
index 65046a4..9130104 100644 (file)
@@ -8,20 +8,15 @@
 
 // Make sure that a std::vector containing move-only types can't be copied.
 
-// UNSUPPORTED: c++03
+// UNSUPPORTED: c++03 && !stdlib=libc++
 
 #include <vector>
 
-struct move_only
-{
-    move_only() = default;
-    move_only(move_only&&) = default;
-    move_only& operator=(move_only&&) = default;
-};
+#include "MoveOnly.h"
 
 int main(int, char**)
 {
-    std::vector<move_only> v;
-    std::vector<move_only> copy = v; // expected-error-re@* {{{{(no matching function for call to 'construct_at')|(call to implicitly-deleted copy constructor of 'move_only')}}}}
+    std::vector<MoveOnly> v;
+    std::vector<MoveOnly> copy = v; // expected-error-re@* {{{{(no matching function for call to 'construct_at')|(call to implicitly-deleted copy constructor of 'MoveOnly')|(call to deleted constructor of 'MoveOnly')}}}}
     return 0;
 }
index cae17b3..05b29c4 100644 (file)
@@ -6,7 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 
-// UNSUPPORTED: c++03
+// UNSUPPORTED: c++03 && !stdlib=libc++
 
 // <vector>
 
 
 void test() {
   {
-    std::vector<operator_hijacker> vo{};
-    std::vector<operator_hijacker> v{std::move(vo)};
+    std::vector<operator_hijacker> vo;
+    std::vector<operator_hijacker> v(std::move(vo));
   }
   {
-    std::vector<operator_hijacker> vo{};
-    std::vector<operator_hijacker> v{std::move(vo), std::allocator<operator_hijacker>{}};
+    std::vector<operator_hijacker> vo;
+    std::vector<operator_hijacker> v(std::move(vo), std::allocator<operator_hijacker>());
   }
 }
index 8c797d1..046f09f 100644 (file)
@@ -6,7 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 
-// UNSUPPORTED: c++03
+// UNSUPPORTED: c++03 && !stdlib=libc++
 
 // <vector>
 
@@ -72,8 +72,8 @@ int main(int, char**)
         assert(is_contiguous_container_asan_correct(c2));
     }
     {
-        std::vector<MoveOnly, min_allocator<MoveOnly> > l(min_allocator<MoveOnly>{});
-        std::vector<MoveOnly, min_allocator<MoveOnly> > lo(min_allocator<MoveOnly>{});
+        std::vector<MoveOnly, min_allocator<MoveOnly> > l((min_allocator<MoveOnly>()));
+        std::vector<MoveOnly, min_allocator<MoveOnly> > lo((min_allocator<MoveOnly>()));
         assert(is_contiguous_container_asan_correct(l));
         assert(is_contiguous_container_asan_correct(lo));
         for (int i = 1; i <= 3; ++i)
@@ -91,12 +91,12 @@ int main(int, char**)
     }
     {
         int a1[] = {1, 3, 7, 9, 10};
-        std::vector<int, min_allocator<int>> c1(a1, a1+sizeof(a1)/sizeof(a1[0]));
+        std::vector<int, min_allocator<int> > c1(a1, a1+sizeof(a1)/sizeof(a1[0]));
         assert(is_contiguous_container_asan_correct(c1));
-        std::vector<int, min_allocator<int>>::const_iterator i = c1.begin();
-        std::vector<int, min_allocator<int>> c2 = std::move(c1);
+        std::vector<int, min_allocator<int> >::const_iterator i = c1.begin();
+        std::vector<int, min_allocator<int> > c2 = std::move(c1);
         assert(is_contiguous_container_asan_correct(c2));
-        std::vector<int, min_allocator<int>>::iterator j = c2.erase(i);
+        std::vector<int, min_allocator<int> >::iterator j = c2.erase(i);
         assert(*j == 3);
         assert(is_contiguous_container_asan_correct(c2));
     }
index b529211..3f6b3fe 100644 (file)
@@ -6,7 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 
-// UNSUPPORTED: c++03
+// UNSUPPORTED: c++03 && !stdlib=libc++
 
 // <vector>
 
@@ -77,8 +77,8 @@ int main(int, char**)
         assert(is_contiguous_container_asan_correct(l2));
     }
     {
-        std::vector<MoveOnly, min_allocator<MoveOnly> > l(min_allocator<MoveOnly>{});
-        std::vector<MoveOnly, min_allocator<MoveOnly> > lo(min_allocator<MoveOnly>{});
+        std::vector<MoveOnly, min_allocator<MoveOnly> > l((min_allocator<MoveOnly>()));
+        std::vector<MoveOnly, min_allocator<MoveOnly> > lo((min_allocator<MoveOnly>()));
         assert(is_contiguous_container_asan_correct(l));
         assert(is_contiguous_container_asan_correct(lo));
         for (int i = 1; i <= 3; ++i)
index cc55967..bc85f3e 100644 (file)
@@ -6,7 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 
-// UNSUPPORTED: c++03
+// UNSUPPORTED: c++03 && !stdlib=libc++
 
 // <vector>
 
@@ -109,8 +109,8 @@ int main(int, char**)
         assert(is_contiguous_container_asan_correct(c));
     }
     {
-        std::vector<A, min_allocator<A>> c;
-        std::vector<A, min_allocator<A>>::iterator i = c.emplace(c.cbegin(), 2, 3.5);
+        std::vector<A, min_allocator<A> > c;
+        std::vector<A, min_allocator<A> >::iterator i = c.emplace(c.cbegin(), 2, 3.5);
         assert(i == c.begin());
         assert(c.size() == 1);
         assert(c.front().geti() == 2);
index c375933..5cf38f2 100644 (file)
@@ -6,7 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 
-// UNSUPPORTED: c++03
+// UNSUPPORTED: c++03 && !stdlib=libc++
 
 // <vector>
 
@@ -26,9 +26,10 @@ class A
     int i_;
     double d_;
 
-    A(const A&);
-    A& operator=(const A&);
 public:
+    A(const A&) = delete;
+    A& operator=(const A&) = delete;
+
     A(int i, double d)
         : i_(i), d_(d) {}
 
@@ -110,7 +111,7 @@ int main(int, char**)
         assert(is_contiguous_container_asan_correct(c));
     }
     {
-        std::vector<A, min_allocator<A>> c;
+        std::vector<A, min_allocator<A> > c;
 #if TEST_STD_VER > 14
         A& r1 = c.emplace_back(2, 3.5);
         assert(c.size() == 1);
@@ -137,7 +138,7 @@ int main(int, char**)
         assert(is_contiguous_container_asan_correct(c));
     }
     {
-        std::vector<Tag_X, TaggingAllocator<Tag_X>> c;
+        std::vector<Tag_X, TaggingAllocator<Tag_X> > c;
         c.emplace_back();
         assert(c.size() == 1);
         c.emplace_back(1, 2, 3);
index ba49777..11f2460 100644 (file)
@@ -6,7 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 
-// UNSUPPORTED: c++03
+// UNSUPPORTED: c++03 && !stdlib=libc++
 
 // <vector>
 
@@ -21,5 +21,5 @@
 
 void test() {
   std::vector<operator_hijacker> v;
-  v.insert(v.end(), operator_hijacker{});
+  v.insert(v.end(), operator_hijacker());
 }
index 13c6681..fe03f2a 100644 (file)
@@ -6,7 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 
-// UNSUPPORTED: c++03
+// UNSUPPORTED: c++03 && !stdlib=libc++
 
 // <vector>
 
@@ -50,8 +50,8 @@ int main(int, char**)
             assert(v[j] == MoveOnly());
     }
     {
-        std::vector<MoveOnly, min_allocator<MoveOnly>> v(100);
-        std::vector<MoveOnly, min_allocator<MoveOnly>>::iterator i = v.insert(v.cbegin() + 10, MoveOnly(3));
+        std::vector<MoveOnly, min_allocator<MoveOnly> > v(100);
+        std::vector<MoveOnly, min_allocator<MoveOnly> >::iterator i = v.insert(v.cbegin() + 10, MoveOnly(3));
         assert(v.size() == 101);
         assert(is_contiguous_container_asan_correct(v));
         assert(i == v.begin() + 10);
index c8e816a..e7527d4 100644 (file)
@@ -6,7 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 
-// UNSUPPORTED: c++03
+// UNSUPPORTED: c++03 && !stdlib=libc++
 
 // <vector>
 
@@ -83,7 +83,7 @@ int main(int, char**)
             assert(c[j] == MoveOnly(j));
     }
     {
-        std::vector<MoveOnly, min_allocator<MoveOnly>> c;
+        std::vector<MoveOnly, min_allocator<MoveOnly> > c;
         c.push_back(MoveOnly(0));
         assert(c.size() == 1);
         assert(is_contiguous_container_asan_correct(c));
index ea74afc..0ee39f3 100644 (file)
@@ -6,7 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 
-// UNSUPPORTED: c++03
+// UNSUPPORTED: c++03 && !stdlib=libc++
 
 // <vector>
 
@@ -40,7 +40,7 @@ int main(int, char**) {
     x.emplace_back();
   }
   {
-    std::vector<BadUserNoCookie<2>> x;
+    std::vector<BadUserNoCookie<2> > x;
     BadUserNoCookie<2> c;
     x.push_back(c);
   }
index 1bee8db..2d0dadf 100644 (file)
@@ -49,11 +49,7 @@ test()
     static_assert((std::is_same<typename R::difference_type, typename T::difference_type>::value), "");
     static_assert((std::is_same<typename R::pointer, It>::value), "");
     static_assert((std::is_same<typename R::value_type, typename T::value_type>::value), "");
-#if TEST_STD_VER >= 11
     static_assert((std::is_same<typename R::reference, typename R::value_type&&>::value), "");
-#else
-    static_assert((std::is_same<typename R::reference, typename T::reference>::value), "");
-#endif
 #if TEST_STD_VER > 17
     if constexpr (std::is_same_v<typename T::iterator_category, std::contiguous_iterator_tag>) {
         static_assert((std::is_same<typename R::iterator_category, std::random_access_iterator_tag>::value), "");
index 3d7e762..d3c253e 100644 (file)
@@ -6,6 +6,8 @@
 //
 //===----------------------------------------------------------------------===//
 
+// UNSUPPORTED: c++03 && !stdlib=libc++
+
 // <utility>
 
 // template <class T>
@@ -46,20 +48,11 @@ int main(int, char**)
     A a;
     const A ca;
 
-#if TEST_STD_VER >= 11
     static_assert((std::is_same<decltype(std::move_if_noexcept(i)), int&&>::value), "");
     static_assert((std::is_same<decltype(std::move_if_noexcept(ci)), const int&&>::value), "");
     static_assert((std::is_same<decltype(std::move_if_noexcept(a)), A&&>::value), "");
     static_assert((std::is_same<decltype(std::move_if_noexcept(ca)), const A&&>::value), "");
     static_assert((std::is_same<decltype(std::move_if_noexcept(l)), const legacy&>::value), "");
-#else  // C++ < 11
-    // In C++03 we don't have noexcept so we can never move :-(
-    static_assert((std::is_same<decltype(std::move_if_noexcept(i)), const int&>::value), "");
-    static_assert((std::is_same<decltype(std::move_if_noexcept(ci)), const int&>::value), "");
-    static_assert((std::is_same<decltype(std::move_if_noexcept(a)), const A&>::value), "");
-    static_assert((std::is_same<decltype(std::move_if_noexcept(ca)), const A&>::value), "");
-    static_assert((std::is_same<decltype(std::move_if_noexcept(l)), const legacy&>::value), "");
-#endif
 
 #if TEST_STD_VER > 11
     constexpr int i1 = 23;
index 3355777..4178b55 100644 (file)
@@ -11,8 +11,6 @@
 
 #include "test_macros.h"
 
-#if TEST_STD_VER >= 11
-
 #include <cstddef>
 #include <functional>
 
@@ -20,31 +18,35 @@ class MoveOnly
 {
     int data_;
 public:
-    constexpr MoveOnly(int data = 1) : data_(data) {}
+    TEST_CONSTEXPR MoveOnly(int data = 1) : data_(data) {}
+
+    MoveOnly(const MoveOnly&) = delete;
+    MoveOnly& operator=(const MoveOnly&) = delete;
+
     TEST_CONSTEXPR_CXX14 MoveOnly(MoveOnly&& x)
         : data_(x.data_) {x.data_ = 0;}
     TEST_CONSTEXPR_CXX14 MoveOnly& operator=(MoveOnly&& x)
         {data_ = x.data_; x.data_ = 0; return *this;}
 
-    constexpr int get() const {return data_;}
+    TEST_CONSTEXPR int get() const {return data_;}
 
-    friend constexpr bool operator==(const MoveOnly& x, const MoveOnly& y)
+    friend TEST_CONSTEXPR bool operator==(const MoveOnly& x, const MoveOnly& y)
         { return x.data_ == y.data_; }
-    friend constexpr bool operator!=(const MoveOnly& x, const MoveOnly& y)
+    friend TEST_CONSTEXPR bool operator!=(const MoveOnly& x, const MoveOnly& y)
         { return x.data_ != y.data_; }
-    friend constexpr bool operator< (const MoveOnly& x, const MoveOnly& y)
+    friend TEST_CONSTEXPR bool operator< (const MoveOnly& x, const MoveOnly& y)
         { return x.data_ <  y.data_; }
-    friend constexpr bool operator<=(const MoveOnly& x, const MoveOnly& y)
+    friend TEST_CONSTEXPR bool operator<=(const MoveOnly& x, const MoveOnly& y)
         { return x.data_ <= y.data_; }
-    friend constexpr bool operator> (const MoveOnly& x, const MoveOnly& y)
+    friend TEST_CONSTEXPR bool operator> (const MoveOnly& x, const MoveOnly& y)
         { return x.data_ >  y.data_; }
-    friend constexpr bool operator>=(const MoveOnly& x, const MoveOnly& y)
+    friend TEST_CONSTEXPR bool operator>=(const MoveOnly& x, const MoveOnly& y)
         { return x.data_ >= y.data_; }
 
     TEST_CONSTEXPR_CXX14 MoveOnly operator+(const MoveOnly& x) const
-        { return MoveOnly{data_ + x.data_}; }
+        { return MoveOnly(data_ + x.data_); }
     TEST_CONSTEXPR_CXX14 MoveOnly operator*(const MoveOnly& x) const
-        { return MoveOnly{data_ * x.data_}; }
+        { return MoveOnly(data_ * x.data_); }
 
     template<class T, class U>
     friend void operator,(T t, U u) = delete;
@@ -56,9 +58,7 @@ struct std::hash<MoveOnly>
 {
     typedef MoveOnly argument_type;
     typedef size_t result_type;
-    constexpr size_t operator()(const MoveOnly& x) const {return x.get();}
+    TEST_CONSTEXPR size_t operator()(const MoveOnly& x) const {return x.get();}
 };
 
-#endif // TEST_STD_VER >= 11
-
 #endif // MOVEONLY_H
index b532006..741f6fc 100644 (file)
@@ -112,7 +112,6 @@ public:
     }
   }
 
-#if TEST_STD_VER >= 11
   TEST_CONSTEXPR_CXX14 test_allocator(test_allocator&& a) TEST_NOEXCEPT : data_(a.data_), id_(a.id_), stats_(a.stats_) {
     if (stats_ != nullptr) {
       ++stats_->count;
@@ -123,7 +122,6 @@ public:
     a.data_ = test_alloc_base::moved_value;
     a.id_ = test_alloc_base::moved_value;
   }
-#endif
 
   template <class U>
   TEST_CONSTEXPR_CXX14 test_allocator(const test_allocator<U>& a) TEST_NOEXCEPT
@@ -166,14 +164,11 @@ public:
 
   TEST_CONSTEXPR size_type max_size() const TEST_NOEXCEPT { return UINT_MAX / sizeof(T); }
 
-#if TEST_STD_VER < 11
-  void construct(pointer p, const T& val) { ::new (static_cast<void*>(p)) T(val); }
-#else
   template <class U>
   TEST_CONSTEXPR_CXX14 void construct(pointer p, U&& val) {
     ::new (static_cast<void*>(p)) T(std::forward<U>(val));
   }
-#endif
+
   TEST_CONSTEXPR_CXX14 void destroy(pointer p) { p->~T(); }
   TEST_CONSTEXPR friend bool operator==(const test_allocator& x, const test_allocator& y) { return x.data_ == y.data_; }
   TEST_CONSTEXPR friend bool operator!=(const test_allocator& x, const test_allocator& y) { return !(x == y); }
@@ -358,8 +353,6 @@ public:
 #endif
 };
 
-#if TEST_STD_VER >= 11
-
 struct Ctor_Tag {};
 
 template <typename T>
@@ -369,15 +362,15 @@ struct Tag_X {
   // All constructors must be passed the Tag type.
 
   // DefaultInsertable into vector<X, TaggingAllocator<X>>,
-  constexpr Tag_X(Ctor_Tag) {}
+  TEST_CONSTEXPR Tag_X(Ctor_Tag) {}
   // CopyInsertable into vector<X, TaggingAllocator<X>>,
-  constexpr Tag_X(Ctor_Tag, const Tag_X&) {}
+  TEST_CONSTEXPR Tag_X(Ctor_Tag, const Tag_X&) {}
   // MoveInsertable into vector<X, TaggingAllocator<X>>, and
-  constexpr Tag_X(Ctor_Tag, Tag_X&&) {}
+  TEST_CONSTEXPR Tag_X(Ctor_Tag, Tag_X&&) {}
 
   // EmplaceConstructible into vector<X, TaggingAllocator<X>> from args.
   template <typename... Args>
-  constexpr Tag_X(Ctor_Tag, Args&&...) {}
+  TEST_CONSTEXPR Tag_X(Ctor_Tag, Args&&...) {}
 
   // not DefaultConstructible, CopyConstructible or MoveConstructible.
   Tag_X() = delete;
@@ -403,11 +396,11 @@ public:
   TaggingAllocator() = default;
 
   template <typename U>
-  constexpr TaggingAllocator(const TaggingAllocator<U>&){};
+  TEST_CONSTEXPR TaggingAllocator(const TaggingAllocator<U>&) {}
 
   template <typename... Args>
   void construct(Tag_X* p, Args&&... args) {
-    ::new ((void*)p) Tag_X(Ctor_Tag{}, std::forward<Args>(args)...);
+    ::new ((void*)p) Tag_X(Ctor_Tag(), std::forward<Args>(args)...);
   }
 
   template <typename U>
@@ -415,10 +408,9 @@ public:
     p->~U();
   }
 
-  TEST_CONSTEXPR_CXX20 T* allocate(std::size_t n) { return std::allocator<T>{}.allocate(n); }
-  TEST_CONSTEXPR_CXX20 void deallocate(T* p, std::size_t n) { std::allocator<T>{}.deallocate(p, n); }
+  TEST_CONSTEXPR_CXX20 T* allocate(std::size_t n) { return std::allocator<T>().allocate(n); }
+  TEST_CONSTEXPR_CXX20 void deallocate(T* p, std::size_t n) { std::allocator<T>().deallocate(p, n); }
 };
-#endif
 
 template <std::size_t MaxAllocs>
 struct limited_alloc_handle {