From c204c130fabdffa131d487ec1c701fc95dba0ffe Mon Sep 17 00:00:00 2001 From: Marshall Clow Date: Thu, 27 Feb 2014 02:11:50 +0000 Subject: [PATCH] LWG issue #2188: Reverse iterator does not fully support targets that overload operator&. Also mark #2272 and #2299 as complete; libc++ already implements them. llvm-svn: 202339 --- libcxx/include/iterator | 3 +- .../reverse.iter.opref/op_arrow.pass.cpp | 39 +++++++++++++++++++ libcxx/www/cxx1y_status.html | 6 +-- 3 files changed, 44 insertions(+), 4 deletions(-) diff --git a/libcxx/include/iterator b/libcxx/include/iterator index 28a946cb9361..b1bcdfc10b0e 100644 --- a/libcxx/include/iterator +++ b/libcxx/include/iterator @@ -327,6 +327,7 @@ template auto crend(const C& c) -> decltype(std::rend(c)); // */ #include <__config> +#include <__functional_base> #include #include #include @@ -549,7 +550,7 @@ public: : __t(__u.base()), current(__u.base()) {} _LIBCPP_INLINE_VISIBILITY _Iter base() const {return current;} _LIBCPP_INLINE_VISIBILITY reference operator*() const {__t = current; return *--__t;} - _LIBCPP_INLINE_VISIBILITY pointer operator->() const {return &(operator*());} + _LIBCPP_INLINE_VISIBILITY pointer operator->() const {return _VSTD::addressof(operator*());} _LIBCPP_INLINE_VISIBILITY reverse_iterator& operator++() {--current; return *this;} _LIBCPP_INLINE_VISIBILITY reverse_iterator operator++(int) {reverse_iterator __tmp(*this); --current; return __tmp;} diff --git a/libcxx/test/iterators/predef.iterators/reverse.iterators/reverse.iter.ops/reverse.iter.opref/op_arrow.pass.cpp b/libcxx/test/iterators/predef.iterators/reverse.iterators/reverse.iter.ops/reverse.iter.opref/op_arrow.pass.cpp index 1aa77fd7c355..fc57deab6789 100644 --- a/libcxx/test/iterators/predef.iterators/reverse.iterators/reverse.iter.ops/reverse.iter.opref/op_arrow.pass.cpp +++ b/libcxx/test/iterators/predef.iterators/reverse.iterators/reverse.iter.ops/reverse.iter.opref/op_arrow.pass.cpp @@ -17,6 +17,7 @@ // http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#198 #include +#include #include class A @@ -61,9 +62,47 @@ test(It i, typename std::iterator_traits::value_type x) assert(r->get() == x.get()); } +class B +{ + int data_; +public: + B(int d=1) : data_(d) {} + ~B() {data_ = -1;} + + int get() const {return data_;} + + friend bool operator==(const B& x, const B& y) + {return x.data_ == y.data_;} + const B *operator&() const { return nullptr; } + B *operator&() { return nullptr; } +}; + int main() { test(weird_iterator(A()), A()); A a; test(&a+1, A()); + + { + std::list l; + l.push_back(B(0)); + l.push_back(B(1)); + l.push_back(B(2)); + + { + std::list::const_iterator i = l.begin(); + assert ( i->get() == 0 ); ++i; + assert ( i->get() == 1 ); ++i; + assert ( i->get() == 2 ); ++i; + assert ( i == l.end ()); + } + + { + std::list::const_reverse_iterator ri = l.rbegin(); + assert ( ri->get() == 2 ); ++ri; + assert ( ri->get() == 1 ); ++ri; + assert ( ri->get() == 0 ); ++ri; + assert ( ri == l.rend ()); + } + } } diff --git a/libcxx/www/cxx1y_status.html b/libcxx/www/cxx1y_status.html index 827e3950d3de..e92d67afad4f 100644 --- a/libcxx/www/cxx1y_status.html +++ b/libcxx/www/cxx1y_status.html @@ -220,7 +220,7 @@ 2257Simplify container requirements with the new algorithmsIssaquahComplete 2268Setting a default argument in the declaration of a member function assign of std::basic_stringIssaquah 2271regex_traits::lookup_classname specification unclearIssaquah - 2272quoted should use char_traits::eq for character comparisonIssaquah + 2272quoted should use char_traits::eq for character comparisonIssaquahComplete 2278User-defined literals for Standard Library typesIssaquahComplete 2280begin / end for arrays should be constexpr and noexceptIssaquahComplete 2285make_reverse_iteratorIssaquah @@ -228,11 +228,11 @@ 2299Effects of inaccessible key_compare::is_transparent type are not clearIssaquahComplete 1450Contradiction in regex_constantsIssaquah - 2003String exception inconsistency in erase.Issaquah + 2003String exception inconsistency in erase.IssaquahComplete 2112User-defined classes that cannot be derived fromIssaquah 2132std::function ambiguityIssaquah 2182Container::[const_]reference types are misleadingly specifiedIssaquah - 2188Reverse iterator does not fully support targets that overload operator&Issaquah + 2188Reverse iterator does not fully support targets that overload operator&IssaquahComplete 2193Default constructors for standard library containers are explicitIssaquah 2205Problematic postconditions of regex_match and regex_searchIssaquah 2213Return value of std::regex_replaceIssaquah