diff --git a/libcxx/include/algorithm b/libcxx/include/algorithm --- a/libcxx/include/algorithm +++ b/libcxx/include/algorithm @@ -895,7 +895,7 @@ _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 @@ _Size __count, const _Tp& __value_, _BinaryPredicate __pred) { return _VSTD::__search_n::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 @@ 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 @@ >::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 @@ >::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 @@ _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 @@ _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 --- a/libcxx/include/iterator +++ b/libcxx/include/iterator @@ -663,9 +663,9 @@ { _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 @@ -692,7 +692,7 @@ typename iterator_traits<_InputIter>::difference_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 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 --- /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 +// +//===----------------------------------------------------------------------===// + +// + +#include + +#include "test_macros.h" + +struct Incomplete; +template struct Holder { T t; }; + +template +struct Intable { + operator int() const { return 1; } +}; + +int main() { + Holder *a[2] = {}; + Holder **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 >()); + (void)std::distance(p, p); +}