Implement LWG 2360: 'reverse_iterator::operator*() is unimplementable'. Note that this is a (small) behavior change in the library. Reverse iterators whose base iterators' operator* return references to 'within themselves' have been sacrificed to the greater goal of avoiding data races.
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@203587 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
d3849253ce
commit
b1ead689be
@ -536,8 +536,6 @@ class _LIBCPP_TYPE_VIS_ONLY reverse_iterator
|
|||||||
typename iterator_traits<_Iter>::pointer,
|
typename iterator_traits<_Iter>::pointer,
|
||||||
typename iterator_traits<_Iter>::reference>
|
typename iterator_traits<_Iter>::reference>
|
||||||
{
|
{
|
||||||
private:
|
|
||||||
mutable _Iter __t;
|
|
||||||
protected:
|
protected:
|
||||||
_Iter current;
|
_Iter current;
|
||||||
public:
|
public:
|
||||||
@ -547,11 +545,11 @@ public:
|
|||||||
typedef typename iterator_traits<_Iter>::pointer pointer;
|
typedef typename iterator_traits<_Iter>::pointer pointer;
|
||||||
|
|
||||||
_LIBCPP_INLINE_VISIBILITY reverse_iterator() : current() {}
|
_LIBCPP_INLINE_VISIBILITY reverse_iterator() : current() {}
|
||||||
_LIBCPP_INLINE_VISIBILITY explicit reverse_iterator(_Iter __x) : __t(__x), current(__x) {}
|
_LIBCPP_INLINE_VISIBILITY explicit reverse_iterator(_Iter __x) : current(__x) {}
|
||||||
template <class _Up> _LIBCPP_INLINE_VISIBILITY reverse_iterator(const reverse_iterator<_Up>& __u)
|
template <class _Up> _LIBCPP_INLINE_VISIBILITY reverse_iterator(const reverse_iterator<_Up>& __u)
|
||||||
: __t(__u.base()), current(__u.base()) {}
|
: current(__u.base()) {}
|
||||||
_LIBCPP_INLINE_VISIBILITY _Iter base() const {return current;}
|
_LIBCPP_INLINE_VISIBILITY _Iter base() const {return current;}
|
||||||
_LIBCPP_INLINE_VISIBILITY reference operator*() const {__t = current; return *--__t;}
|
_LIBCPP_INLINE_VISIBILITY reference operator*() const {_Iter __tmp = current; return *--__tmp;}
|
||||||
_LIBCPP_INLINE_VISIBILITY pointer operator->() const {return _VSTD::addressof(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++() {--current; return *this;}
|
||||||
_LIBCPP_INLINE_VISIBILITY reverse_iterator operator++(int)
|
_LIBCPP_INLINE_VISIBILITY reverse_iterator operator++(int)
|
||||||
|
@ -15,6 +15,8 @@
|
|||||||
|
|
||||||
// Be sure to respect LWG 198:
|
// Be sure to respect LWG 198:
|
||||||
// http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#198
|
// http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#198
|
||||||
|
// LWG 198 was superseded by LWG 2360
|
||||||
|
// http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2360
|
||||||
|
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
@ -30,26 +32,6 @@ public:
|
|||||||
{return x.data_ == y.data_;}
|
{return x.data_ == y.data_;}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class It>
|
|
||||||
class weird_iterator
|
|
||||||
{
|
|
||||||
It it_;
|
|
||||||
public:
|
|
||||||
typedef It value_type;
|
|
||||||
typedef std::bidirectional_iterator_tag iterator_category;
|
|
||||||
typedef std::ptrdiff_t difference_type;
|
|
||||||
typedef It* pointer;
|
|
||||||
typedef It& reference;
|
|
||||||
|
|
||||||
weird_iterator() {}
|
|
||||||
explicit weird_iterator(It it) : it_(it) {}
|
|
||||||
~weird_iterator() {it_ = It();}
|
|
||||||
|
|
||||||
reference operator*() {return it_;}
|
|
||||||
|
|
||||||
weird_iterator& operator--() {return *this;}
|
|
||||||
};
|
|
||||||
|
|
||||||
template <class It>
|
template <class It>
|
||||||
void
|
void
|
||||||
test(It i, typename std::iterator_traits<It>::value_type x)
|
test(It i, typename std::iterator_traits<It>::value_type x)
|
||||||
@ -60,7 +42,6 @@ test(It i, typename std::iterator_traits<It>::value_type x)
|
|||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
test(weird_iterator<A>(A()), A());
|
|
||||||
A a;
|
A a;
|
||||||
test(&a+1, A());
|
test(&a+1, A());
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,9 @@
|
|||||||
|
|
||||||
// Be sure to respect LWG 198:
|
// Be sure to respect LWG 198:
|
||||||
// http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#198
|
// http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#198
|
||||||
|
// LWG 198 was superseded by LWG 2360
|
||||||
|
// http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2360
|
||||||
|
|
||||||
|
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
#include <list>
|
#include <list>
|
||||||
@ -33,27 +36,6 @@ public:
|
|||||||
{return x.data_ == y.data_;}
|
{return x.data_ == y.data_;}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class It>
|
|
||||||
class weird_iterator
|
|
||||||
{
|
|
||||||
It it_;
|
|
||||||
public:
|
|
||||||
typedef It value_type;
|
|
||||||
typedef std::bidirectional_iterator_tag iterator_category;
|
|
||||||
typedef std::ptrdiff_t difference_type;
|
|
||||||
typedef It* pointer;
|
|
||||||
typedef It& reference;
|
|
||||||
|
|
||||||
weird_iterator() {}
|
|
||||||
explicit weird_iterator(It it) : it_(it) {}
|
|
||||||
~weird_iterator() {it_ = It();}
|
|
||||||
|
|
||||||
reference operator*() {return it_;}
|
|
||||||
pointer operator->() {return &it_;}
|
|
||||||
|
|
||||||
weird_iterator& operator--() {return *this;}
|
|
||||||
};
|
|
||||||
|
|
||||||
template <class It>
|
template <class It>
|
||||||
void
|
void
|
||||||
test(It i, typename std::iterator_traits<It>::value_type x)
|
test(It i, typename std::iterator_traits<It>::value_type x)
|
||||||
@ -79,7 +61,6 @@ public:
|
|||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
test(weird_iterator<A>(A()), A());
|
|
||||||
A a;
|
A a;
|
||||||
test(&a+1, A());
|
test(&a+1, A());
|
||||||
|
|
||||||
|
@ -265,7 +265,7 @@
|
|||||||
<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2356">2356</a></td><td>Stability of erasure in unordered associative containers</td><td>Issaquah</td><td>Complete</td></tr>
|
<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2356">2356</a></td><td>Stability of erasure in unordered associative containers</td><td>Issaquah</td><td>Complete</td></tr>
|
||||||
<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2357">2357</a></td><td>Remaining "Assignable" requirement</td><td>Issaquah</td><td>Complete</td></tr>
|
<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2357">2357</a></td><td>Remaining "Assignable" requirement</td><td>Issaquah</td><td>Complete</td></tr>
|
||||||
<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2359">2359</a></td><td>How does regex_constants::nosubs affect basic_regex::mark_count()?</td><td>Issaquah</td><td>Complete</td></tr>
|
<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2359">2359</a></td><td>How does regex_constants::nosubs affect basic_regex::mark_count()?</td><td>Issaquah</td><td>Complete</td></tr>
|
||||||
<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2360">2360</a></td><td>reverse_iterator::operator*() is unimplementable</td><td>Issaquah</td><td></td></tr>
|
<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2360">2360</a></td><td>reverse_iterator::operator*() is unimplementable</td><td>Issaquah</td><td>Complete</td></tr>
|
||||||
<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2104">2104</a></td><td>unique_lock move-assignment should not be noexcept</td><td>Issaquah</td><td></td></tr>
|
<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2104">2104</a></td><td>unique_lock move-assignment should not be noexcept</td><td>Issaquah</td><td></td></tr>
|
||||||
<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2186">2186</a></td><td>Incomplete action on async/launch::deferred</td><td>Issaquah</td><td></td></tr>
|
<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2186">2186</a></td><td>Incomplete action on async/launch::deferred</td><td>Issaquah</td><td></td></tr>
|
||||||
<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2075">2075</a></td><td>Progress guarantees, lock-free property, and scheduling assumptions</td><td>Issaquah</td><td></td></tr>
|
<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2075">2075</a></td><td>Progress guarantees, lock-free property, and scheduling assumptions</td><td>Issaquah</td><td></td></tr>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user