[cfe-commits] [libcxx] r124255 - /libcxx/trunk/include/iterator

Douglas Gregor dgregor at apple.com
Tue Jan 25 16:12:48 PST 2011


Author: dgregor
Date: Tue Jan 25 18:12:48 2011
New Revision: 124255

URL: http://llvm.org/viewvc/llvm-project?rev=124255&view=rev
Log:
Teach move_iterator that rvalue references cannot bind to non-function
lvalues, nor can one take the address of an xvalue, by adding
appropriate static_cast's (in the first case) and a temporary (in the
second case).

Modified:
    libcxx/trunk/include/iterator

Modified: libcxx/trunk/include/iterator
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/iterator?rev=124255&r1=124254&r2=124255&view=diff
==============================================================================
--- libcxx/trunk/include/iterator (original)
+++ libcxx/trunk/include/iterator Tue Jan 25 18:12:48 2011
@@ -902,8 +902,13 @@
     template <class _Up> _LIBCPP_INLINE_VISIBILITY move_iterator(const move_iterator<_Up>& __u)
         : __i(__u.base()) {}
     _LIBCPP_INLINE_VISIBILITY _Iter base() const {return __i;}
-    _LIBCPP_INLINE_VISIBILITY reference operator*() const {return *__i;}
-    _LIBCPP_INLINE_VISIBILITY pointer  operator->() const {return &(operator*());}
+    _LIBCPP_INLINE_VISIBILITY reference operator*() const {
+      return static_cast<reference>(*__i);
+    }
+    _LIBCPP_INLINE_VISIBILITY pointer  operator->() const {
+      typename iterator_traits<iterator_type>::reference __ref = *__i;
+      return &__ref;
+    }
     _LIBCPP_INLINE_VISIBILITY move_iterator& operator++() {++__i; return *this;}
     _LIBCPP_INLINE_VISIBILITY move_iterator  operator++(int)
         {move_iterator __tmp(*this); ++__i; return __tmp;}
@@ -919,7 +924,9 @@
     _LIBCPP_INLINE_VISIBILITY move_iterator& operator-=(difference_type __n)
         {__i -= __n; return *this;}
     _LIBCPP_INLINE_VISIBILITY reference         operator[](difference_type __n) const
-        {return __i[__n];}
+    {
+      return static_cast<reference>(__i[__n]);
+    }
 };
 
 template <class _Iter1, class _Iter2>





More information about the cfe-commits mailing list