[libcxx] r262866 - non-member swap for array was mistakenly taking const ref params. Fixed and added test. Thanks to Ben Craig for the catch

Marshall Clow via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 7 13:57:10 PST 2016


Author: marshall
Date: Mon Mar  7 15:57:10 2016
New Revision: 262866

URL: http://llvm.org/viewvc/llvm-project?rev=262866&view=rev
Log:
non-member swap for array was mistakenly taking const ref params. Fixed and added test. Thanks to Ben Craig for the catch

Modified:
    libcxx/trunk/include/array
    libcxx/trunk/test/std/containers/sequences/array/array.swap/swap.pass.cpp

Modified: libcxx/trunk/include/array
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/array?rev=262866&r1=262865&r2=262866&view=diff
==============================================================================
--- libcxx/trunk/include/array (original)
+++ libcxx/trunk/include/array Mon Mar  7 15:57:10 2016
@@ -279,7 +279,7 @@ typename enable_if
     __is_swappable<_Tp>::value,
     void
 >::type
-swap(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
+swap(array<_Tp, _Size>& __x, array<_Tp, _Size>& __y)
                                   _NOEXCEPT_(__is_nothrow_swappable<_Tp>::value)
 {
     __x.swap(__y);

Modified: libcxx/trunk/test/std/containers/sequences/array/array.swap/swap.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/containers/sequences/array/array.swap/swap.pass.cpp?rev=262866&r1=262865&r2=262866&view=diff
==============================================================================
--- libcxx/trunk/test/std/containers/sequences/array/array.swap/swap.pass.cpp (original)
+++ libcxx/trunk/test/std/containers/sequences/array/array.swap/swap.pass.cpp Mon Mar  7 15:57:10 2016
@@ -10,9 +10,10 @@
 // <array>
 
 // void swap(array& a);
+// namespace std { void swap(array<T, N> &x, array<T, N> &y);
 
-#include <array>
 #include <cassert>
+#include <array>
 
 // std::array is explicitly allowed to be initialized with A a = { init-list };.
 // Disable the missing braces warning for this reason.
@@ -37,6 +38,22 @@ int main()
     }
     {
         typedef double T;
+        typedef std::array<T, 3> C;
+        C c1 = {1, 2, 3.5};
+        C c2 = {4, 5, 6.5};
+        std::swap(c1, c2);
+        assert(c1.size() == 3);
+        assert(c1[0] == 4);
+        assert(c1[1] == 5);
+        assert(c1[2] == 6.5);
+        assert(c2.size() == 3);
+        assert(c2[0] == 1);
+        assert(c2[1] == 2);
+        assert(c2[2] == 3.5);
+    }
+
+    {
+        typedef double T;
         typedef std::array<T, 0> C;
         C c1 = {};
         C c2 = {};
@@ -44,4 +61,14 @@ int main()
         assert(c1.size() == 0);
         assert(c2.size() == 0);
     }
+    {
+        typedef double T;
+        typedef std::array<T, 0> C;
+        C c1 = {};
+        C c2 = {};
+        std::swap(c1, c2);
+        assert(c1.size() == 0);
+        assert(c2.size() == 0);
+    }
+
 }




More information about the cfe-commits mailing list