Skip to content

Commit f03430f

Browse files
author
Xiaoyang Liu
authored
[libc++] LWG3672: common_iterator::operator->() should return by value (#87899)
## Abstract This pull request implements LWG3672: `common_iterator::operator->()` should return by value. The current implementation specifies that this function should return the underlying pointer by reference (`T* const&`), but it would be more intuitive to return it by value (`T*`). ## Reference - [Draft C++ Standard: [common.iter.access]](https://eel.is/c++draft/common.iter.access) - [LWG3672](https://cplusplus.github.io/LWG/issue3672)
1 parent bd6c358 commit f03430f

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

libcxx/docs/Status/Cxx23Issues.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@
165165
"`3659 <https://wg21.link/LWG3659>`__","Consider ``ATOMIC_FLAG_INIT`` undeprecation","July 2022","|Complete|","15.0"
166166
"`3670 <https://wg21.link/LWG3670>`__","``Cpp17InputIterators`` don't have integer-class difference types","July 2022","","","|ranges|"
167167
"`3671 <https://wg21.link/LWG3671>`__","``atomic_fetch_xor`` missing from ``stdatomic.h``","July 2022","",""
168-
"`3672 <https://wg21.link/LWG3672>`__","``common_iterator::operator->()`` should return by value","July 2022","","","|ranges|"
168+
"`3672 <https://wg21.link/LWG3672>`__","``common_iterator::operator->()`` should return by value","July 2022","|Complete|","19.0","|ranges|"
169169
"`3683 <https://wg21.link/LWG3683>`__","``operator==`` for ``polymorphic_allocator`` cannot deduce template argument in common cases","July 2022","",""
170170
"`3687 <https://wg21.link/LWG3687>`__","``expected<cv void, E>`` move constructor should move","July 2022","|Complete|","16.0"
171171
"`3692 <https://wg21.link/LWG3692>`__","``zip_view::iterator``'s ``operator<=>`` is overconstrained","July 2022","","","|ranges| |spaceship|"

libcxx/include/__iterator/common_iterator.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ class common_iterator {
124124
}
125125

126126
template <class _I2 = _Iter>
127-
_LIBCPP_HIDE_FROM_ABI decltype(auto) operator->() const
127+
_LIBCPP_HIDE_FROM_ABI auto operator->() const
128128
requires indirectly_readable<const _I2> && (requires(const _I2& __i) {
129129
__i.operator->();
130130
} || is_reference_v<iter_reference_t<_I2>> || constructible_from<iter_value_t<_I2>, iter_reference_t<_I2>>)

libcxx/test/std/iterators/predef.iterators/iterators.common/arrow.pass.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
// UNSUPPORTED: c++03, c++11, c++14, c++17
1010

11-
// decltype(auto) operator->() const
11+
// auto operator->() const
1212
// requires see below;
1313

1414
#include <iterator>
@@ -28,11 +28,11 @@ void test() {
2828
using Common = std::common_iterator<Iterator, sentinel_wrapper<Iterator>>;
2929

3030
Common common(iter);
31-
std::same_as<Iterator> auto result = common.operator->();
31+
std::same_as<Iterator> decltype(auto) result = common.operator->();
3232
assert(base(result) == buffer);
3333

3434
Common const ccommon(iter);
35-
std::same_as<Iterator> auto cresult = ccommon.operator->();
35+
std::same_as<Iterator> decltype(auto) cresult = ccommon.operator->();
3636
assert(base(cresult) == buffer);
3737
};
3838

@@ -48,11 +48,11 @@ void test() {
4848
using Common = std::common_iterator<Iterator, sentinel_type<int*>>;
4949

5050
Common common(iter);
51-
std::same_as<int*> auto result = common.operator->();
51+
std::same_as<int*> decltype(auto) result = common.operator->();
5252
assert(result == buffer);
5353

5454
Common const ccommon(iter);
55-
std::same_as<int*> auto cresult = ccommon.operator->();
55+
std::same_as<int*> decltype(auto) cresult = ccommon.operator->();
5656
assert(cresult == buffer);
5757
};
5858

@@ -72,14 +72,14 @@ void test() {
7272
using Common = std::common_iterator<Iterator, sentinel_type<int*>>;
7373

7474
Common common(iter);
75-
auto proxy = common.operator->();
76-
std::same_as<int const*> auto result = proxy.operator->();
75+
auto proxy = common.operator->();
76+
std::same_as<int const*> decltype(auto) result = proxy.operator->();
7777
assert(result != buffer); // we copied to a temporary proxy
7878
assert(*result == *buffer);
7979

8080
Common const ccommon(iter);
81-
auto cproxy = ccommon.operator->();
82-
std::same_as<int const*> auto cresult = cproxy.operator->();
81+
auto cproxy = ccommon.operator->();
82+
std::same_as<int const*> decltype(auto) cresult = cproxy.operator->();
8383
assert(cresult != buffer); // we copied to a temporary proxy
8484
assert(*cresult == *buffer);
8585
};

0 commit comments

Comments
 (0)