[libcxx-commits] [libcxx] c0428b3 - [libc++] ADL-proof <iterator>. `__convert_to_integral` is not a customization point.

Arthur O'Dwyer via libcxx-commits libcxx-commits at lists.llvm.org
Tue Dec 8 08:20:15 PST 2020


Author: Arthur O'Dwyer
Date: 2020-12-08T11:19:16-05:00
New Revision: c0428b3c0c1f3b78d39ceaf909908800fb7aabe3

URL: https://github.com/llvm/llvm-project/commit/c0428b3c0c1f3b78d39ceaf909908800fb7aabe3
DIFF: https://github.com/llvm/llvm-project/commit/c0428b3c0c1f3b78d39ceaf909908800fb7aabe3.diff

LOG: [libc++] ADL-proof <iterator>. `__convert_to_integral` is not a customization point.

The interesting change here is that we no longer consider `__convert_to_integral`
an ADL customization point for the user's types. I think the new behavior
is defensible. The old behavior had come from D7449, where Marshall explicitly
said "people can't define their own [`__convert_to_integral` overloads]."

Differential Revision: https://reviews.llvm.org/D92814

Added: 
    libcxx/test/std/iterators/iterator.primitives/iterator.operations/robust_against_adl.pass.cpp

Modified: 
    libcxx/include/algorithm
    libcxx/include/iterator

Removed: 
    


################################################################################
diff  --git a/libcxx/include/algorithm b/libcxx/include/algorithm
index 3bb6c7829bcf..7944f9b6e1aa 100644
--- a/libcxx/include/algorithm
+++ b/libcxx/include/algorithm
@@ -895,7 +895,7 @@ inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
 _InputIterator
 for_each_n(_InputIterator __first, _Size __orig_n, _Function __f)
 {
-    typedef decltype(__convert_to_integral(__orig_n)) _IntegralSize;
+    typedef decltype(_VSTD::__convert_to_integral(__orig_n)) _IntegralSize;
     _IntegralSize __n = __orig_n;
     while (__n > 0)
     {
@@ -1614,7 +1614,7 @@ search_n(_ForwardIterator __first, _ForwardIterator __last,
          _Size __count, const _Tp& __value_, _BinaryPredicate __pred)
 {
     return _VSTD::__search_n<typename add_lvalue_reference<_BinaryPredicate>::type>
-           (__first, __last, __convert_to_integral(__count), __value_, __pred,
+           (__first, __last, _VSTD::__convert_to_integral(__count), __value_, __pred,
            typename iterator_traits<_ForwardIterator>::iterator_category());
 }
 
@@ -1625,7 +1625,7 @@ _ForwardIterator
 search_n(_ForwardIterator __first, _ForwardIterator __last, _Size __count, const _Tp& __value_)
 {
     typedef typename iterator_traits<_ForwardIterator>::value_type __v;
-    return _VSTD::search_n(__first, __last, __convert_to_integral(__count),
+    return _VSTD::search_n(__first, __last, _VSTD::__convert_to_integral(__count),
                            __value_, __equal_to<__v, _Tp>());
 }
 
@@ -1827,7 +1827,7 @@ typename enable_if
 >::type
 copy_n(_InputIterator __first, _Size __orig_n, _OutputIterator __result)
 {
-    typedef decltype(__convert_to_integral(__orig_n)) _IntegralSize;
+    typedef decltype(_VSTD::__convert_to_integral(__orig_n)) _IntegralSize;
     _IntegralSize __n = __orig_n;
     if (__n > 0)
     {
@@ -1852,7 +1852,7 @@ typename enable_if
 >::type
 copy_n(_InputIterator __first, _Size __orig_n, _OutputIterator __result)
 {
-    typedef decltype(__convert_to_integral(__orig_n)) _IntegralSize;
+    typedef decltype(_VSTD::__convert_to_integral(__orig_n)) _IntegralSize;
     _IntegralSize __n = __orig_n;
     return _VSTD::copy(__first, __first + __n, __result);
 }
@@ -2057,7 +2057,7 @@ inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
 _OutputIterator
 fill_n(_OutputIterator __first, _Size __n, const _Tp& __value_)
 {
-   return _VSTD::__fill_n(__first, __convert_to_integral(__n), __value_);
+   return _VSTD::__fill_n(__first, _VSTD::__convert_to_integral(__n), __value_);
 }
 
 // fill
@@ -2105,7 +2105,7 @@ inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
 _OutputIterator
 generate_n(_OutputIterator __first, _Size __orig_n, _Generator __gen)
 {
-    typedef decltype(__convert_to_integral(__orig_n)) _IntegralSize;
+    typedef decltype(_VSTD::__convert_to_integral(__orig_n)) _IntegralSize;
     _IntegralSize __n = __orig_n;
     for (; __n > 0; ++__first, (void) --__n)
         *__first = __gen();

diff  --git a/libcxx/include/iterator b/libcxx/include/iterator
index 90b5f41132d9..3e1fb610821a 100644
--- a/libcxx/include/iterator
+++ b/libcxx/include/iterator
@@ -663,9 +663,9 @@ void advance(_InputIter& __i, _Distance __orig_n)
 {
     _LIBCPP_ASSERT(__orig_n >= 0 || __is_cpp17_bidirectional_iterator<_InputIter>::value,
                    "Attempt to advance(it, n) with negative n on a non-bidirectional iterator");
-    typedef decltype(__convert_to_integral(__orig_n)) _IntegralSize;
+    typedef decltype(_VSTD::__convert_to_integral(__orig_n)) _IntegralSize;
     _IntegralSize __n = __orig_n;
-    __advance(__i, __n, typename iterator_traits<_InputIter>::iterator_category());
+    _VSTD::__advance(__i, __n, typename iterator_traits<_InputIter>::iterator_category());
 }
 
 template <class _InputIter>
@@ -692,7 +692,7 @@ inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
 typename iterator_traits<_InputIter>::
diff erence_type
 distance(_InputIter __first, _InputIter __last)
 {
-    return __distance(__first, __last, typename iterator_traits<_InputIter>::iterator_category());
+    return _VSTD::__distance(__first, __last, typename iterator_traits<_InputIter>::iterator_category());
 }
 
 template <class _InputIter>

diff  --git a/libcxx/test/std/iterators/iterator.primitives/iterator.operations/robust_against_adl.pass.cpp b/libcxx/test/std/iterators/iterator.primitives/iterator.operations/robust_against_adl.pass.cpp
new file mode 100644
index 000000000000..9dac2976632e
--- /dev/null
+++ b/libcxx/test/std/iterators/iterator.primitives/iterator.operations/robust_against_adl.pass.cpp
@@ -0,0 +1,34 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// <iterator>
+
+#include <iterator>
+
+#include "test_macros.h"
+
+struct Incomplete;
+template<class T> struct Holder { T t; };
+
+template<class>
+struct Intable {
+    operator int() const { return 1; }
+};
+
+int main() {
+    Holder<Incomplete> *a[2] = {};
+    Holder<Incomplete> **p = a;
+#if TEST_STD_VER >= 17
+    p = std::next(p);
+    p = std::prev(p);
+    p = std::next(p, 2);
+    p = std::prev(p, 2);
+#endif
+    std::advance(p, Intable<Holder<Incomplete> >());
+    (void)std::distance(p, p);
+}


        


More information about the libcxx-commits mailing list