[libcxx] r267091 - Fix LWG issue #2106: move_iterators returning prvalues

Eric Fiselier via cfe-commits cfe-commits at lists.llvm.org
Thu Apr 21 17:49:12 PDT 2016


Author: ericwf
Date: Thu Apr 21 19:49:12 2016
New Revision: 267091

URL: http://llvm.org/viewvc/llvm-project?rev=267091&view=rev
Log:
Fix LWG issue #2106: move_iterators returning prvalues

Modified:
    libcxx/trunk/include/iterator
    libcxx/trunk/test/std/iterators/predef.iterators/move.iterators/move.iterator/types.pass.cpp
    libcxx/trunk/www/cxx1z_status.html

Modified: libcxx/trunk/include/iterator
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/iterator?rev=267091&r1=267090&r2=267091&view=diff
==============================================================================
--- libcxx/trunk/include/iterator (original)
+++ libcxx/trunk/include/iterator Thu Apr 21 19:49:12 2016
@@ -951,7 +951,12 @@ public:
     typedef typename iterator_traits<iterator_type>::difference_type difference_type;
     typedef iterator_type pointer;
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
-    typedef value_type&& reference;
+    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

Modified: libcxx/trunk/test/std/iterators/predef.iterators/move.iterators/move.iterator/types.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/iterators/predef.iterators/move.iterators/move.iterator/types.pass.cpp?rev=267091&r1=267090&r2=267091&view=diff
==============================================================================
--- libcxx/trunk/test/std/iterators/predef.iterators/move.iterators/move.iterator/types.pass.cpp (original)
+++ libcxx/trunk/test/std/iterators/predef.iterators/move.iterators/move.iterator/types.pass.cpp Thu Apr 21 19:49:12 2016
@@ -26,8 +26,18 @@
 #include <iterator>
 #include <type_traits>
 
+#include "test_macros.h"
 #include "test_iterators.h"
 
+template <class ValueType, class Reference>
+struct DummyIt {
+  typedef std::forward_iterator_tag iterator_category;
+  typedef ValueType value_type;
+  typedef std::ptrdiff_t difference_type;
+  typedef ValueType* pointer;
+  typedef Reference reference;
+};
+
 template <class It>
 void
 test()
@@ -38,7 +48,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), "");
-#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+#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), "");
@@ -53,4 +63,33 @@ int main()
     test<bidirectional_iterator<char*> >();
     test<random_access_iterator<char*> >();
     test<char*>();
+#if TEST_STD_VER >= 11
+    {
+        typedef DummyIt<int, int> T;
+        typedef std::move_iterator<T> It;
+        static_assert(std::is_same<It::reference, int>::value, "");
+    }
+    {
+        typedef DummyIt<int, std::reference_wrapper<int> > T;
+        typedef std::move_iterator<T> It;
+        static_assert(std::is_same<It::reference, std::reference_wrapper<int> >::value, "");
+    }
+    {
+        // Check that move_iterator uses whatever reference type it's given
+        // when it's not a reference.
+        typedef DummyIt<int, long > T;
+        typedef std::move_iterator<T> It;
+        static_assert(std::is_same<It::reference, long>::value, "");
+    }
+    {
+        typedef DummyIt<int, int&> T;
+        typedef std::move_iterator<T> It;
+        static_assert(std::is_same<It::reference, int&&>::value, "");
+    }
+    {
+        typedef DummyIt<int, int&&> T;
+        typedef std::move_iterator<T> It;
+        static_assert(std::is_same<It::reference, int&&>::value, "");
+    }
+#endif
 }

Modified: libcxx/trunk/www/cxx1z_status.html
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/www/cxx1z_status.html?rev=267091&r1=267090&r2=267091&view=diff
==============================================================================
--- libcxx/trunk/www/cxx1z_status.html (original)
+++ libcxx/trunk/www/cxx1z_status.html Thu Apr 21 19:49:12 2016
@@ -114,7 +114,7 @@
 	<tr><td><a href="http://cplusplus.github.io/LWG/lwg-defects.html#2404">2404</a></td><td><code>mismatch()</code>'s complexity needs to be updated</td><td>Urbana</td><td>Complete</td></tr>
 	<tr><td><a href="http://cplusplus.github.io/LWG/lwg-defects.html#2408">2408</a></td><td>SFINAE-friendly <code>common_type</code> / <code>iterator_traits</code> is missing in C++14</td><td>Urbana</td><td><code>common_type</code> is waiting on <a href="http://cplusplus.github.io/LWG/lwg-defects.html#2465">LWG#2465</a></td></tr>
  	<tr><td></td><td></td><td></td><td></td></tr>
-	<tr><td><a href="http://cplusplus.github.io/LWG/lwg-defects.html#2106">2106</td><td><code>move_iterator</code> wrapping iterators returning prvalues</td><td>Urbana</td><td></td></tr>
+	<tr><td><a href="http://cplusplus.github.io/LWG/lwg-defects.html#2106">2106</td><td><code>move_iterator</code> wrapping iterators returning prvalues</td><td>Urbana</td><td>Complete</td></tr>
 	<tr><td><a href="http://cplusplus.github.io/LWG/lwg-defects.html#2129">2129</td><td>User specializations of <code>std::initializer_list</code></td><td>Urbana</td><td>Complete</td></tr>
 	<tr><td><a href="http://cplusplus.github.io/LWG/lwg-defects.html#2212">2212</td><td><code>tuple_size</code> for <code>const pair</code> request <tuple> header</td><td>Urbana</td><td>Complete</td></tr>
 	<tr><td><a href="http://cplusplus.github.io/LWG/lwg-defects.html#2217">2217</td><td><code>operator==(sub_match, string)</code> slices on embedded '\0's</td><td>Urbana</td><td>Complete</td></tr>




More information about the cfe-commits mailing list