diff options
Diffstat (limited to 'libstdc++-v3')
-rw-r--r-- | libstdc++-v3/include/bits/basic_string.h | 19 | ||||
-rw-r--r-- | libstdc++-v3/include/bits/ptr_traits.h | 4 | ||||
-rw-r--r-- | libstdc++-v3/include/bits/shared_ptr_base.h | 4 | ||||
-rw-r--r-- | libstdc++-v3/include/bits/stl_algo.h | 16 | ||||
-rw-r--r-- | libstdc++-v3/include/bits/stl_iterator.h | 12 | ||||
-rw-r--r-- | libstdc++-v3/include/debug/safe_iterator.h | 17 | ||||
-rw-r--r-- | libstdc++-v3/include/std/ranges | 2 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/24_iterators/normal_iterator/to_address.cc | 19 |
8 files changed, 31 insertions, 62 deletions
diff --git a/libstdc++-v3/include/bits/basic_string.h b/libstdc++-v3/include/bits/basic_string.h index e9b17ea..16e356e 100644 --- a/libstdc++-v3/include/bits/basic_string.h +++ b/libstdc++-v3/include/bits/basic_string.h @@ -1732,18 +1732,25 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 basic_string& assign(_InputIterator __first, _InputIterator __last) { + using _IterTraits = iterator_traits<_InputIterator>; + if constexpr (is_pointer<decltype(std::__niter_base(__first))>::value + && is_same<typename _IterTraits::value_type, + _CharT>::value) + { + __glibcxx_requires_valid_range(__first, __last); + return _M_replace(size_type(0), size(), + std::__niter_base(__first), __last - __first); + } #if __cplusplus >= 202002L - if constexpr (contiguous_iterator<_InputIterator> - && is_same_v<iter_value_t<_InputIterator>, _CharT>) -#else - if constexpr (__is_one_of<_InputIterator, const_iterator, iterator, - const _CharT*, _CharT*>::value) -#endif + else if constexpr (contiguous_iterator<_InputIterator> + && is_same_v<iter_value_t<_InputIterator>, + _CharT>) { __glibcxx_requires_valid_range(__first, __last); return _M_replace(size_type(0), size(), std::__to_address(__first), __last - __first); } +#endif else return *this = basic_string(__first, __last, get_allocator()); } diff --git a/libstdc++-v3/include/bits/ptr_traits.h b/libstdc++-v3/include/bits/ptr_traits.h index ca67fee..cef88f61 100644 --- a/libstdc++-v3/include/bits/ptr_traits.h +++ b/libstdc++-v3/include/bits/ptr_traits.h @@ -211,6 +211,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION return __ptr; } + // This should only be used for pointer-like types (e.g. allocator pointers) + // and (in C++20 and later) for types satisfying std::contiguous_iterator. + // It should not be used for arbitrary random access iterators, because + // they might not be contiguous iterators (e.g. deque::iterator isn't). template<typename _Ptr> constexpr typename std::pointer_traits<_Ptr>::element_type* __to_address(const _Ptr& __ptr) diff --git a/libstdc++-v3/include/bits/shared_ptr_base.h b/libstdc++-v3/include/bits/shared_ptr_base.h index ef0658f..9a7617e 100644 --- a/libstdc++-v3/include/bits/shared_ptr_base.h +++ b/libstdc++-v3/include/bits/shared_ptr_base.h @@ -1560,7 +1560,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION __shared_ptr(unique_ptr<_Yp, _Del>&& __r) : _M_ptr(__r.get()), _M_refcount() { - auto __raw = __to_address(__r.get()); + auto __raw = std::__to_address(__r.get()); _M_refcount = __shared_count<_Lp>(std::move(__r)); _M_enable_shared_from_this_with(__raw); } @@ -1576,7 +1576,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION __shared_ptr(unique_ptr<_Tp1, _Del>&& __r, __sp_array_delete) : _M_ptr(__r.get()), _M_refcount() { - auto __raw = __to_address(__r.get()); + auto __raw = std::__to_address(__r.get()); _M_refcount = __shared_count<_Lp>(std::move(__r)); _M_enable_shared_from_this_with(__raw); } diff --git a/libstdc++-v3/include/bits/stl_algo.h b/libstdc++-v3/include/bits/stl_algo.h index 780bd8e..c10f8aa 100644 --- a/libstdc++-v3/include/bits/stl_algo.h +++ b/libstdc++-v3/include/bits/stl_algo.h @@ -3834,7 +3834,7 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO using _ValT = typename iterator_traits<_InputIterator>::value_type; if constexpr (__can_use_memchr_for_find<_ValT, _Tp>) if constexpr (is_pointer_v<decltype(std::__niter_base(__first))> -#if __cpp_lib_concepts +#if __glibcxx_concepts && __glibcxx_to_address || contiguous_iterator<_InputIterator> #endif ) @@ -3847,11 +3847,17 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO return __last; else if (!__is_constant_evaluated()) { - const void* __p0 = std::__to_address(__first); const int __ival = static_cast<int>(__val); - if (auto __n = std::distance(__first, __last); __n > 0) - if (auto __p1 = __builtin_memchr(__p0, __ival, __n)) - return __first + ((const char*)__p1 - (const char*)__p0); + if (auto __n = __last - __first; __n > 0) + { +#if __glibcxx_concepts && __glibcxx_to_address + const void* __p0 = std::to_address(__first); +#else + const void* __p0 = std::__niter_base(__first); +#endif + if (auto __p1 = __builtin_memchr(__p0, __ival, __n)) + return __first + ((const char*)__p1 - (const char*)__p0); + } return __last; } } diff --git a/libstdc++-v3/include/bits/stl_iterator.h b/libstdc++-v3/include/bits/stl_iterator.h index 1fbc115..46e0d46 100644 --- a/libstdc++-v3/include/bits/stl_iterator.h +++ b/libstdc++-v3/include/bits/stl_iterator.h @@ -1348,18 +1348,6 @@ namespace std _GLIBCXX_VISIBILITY(default) { _GLIBCXX_BEGIN_NAMESPACE_VERSION -#if __cplusplus >= 201103L && __cplusplus <= 201703L - // Need to overload __to_address because the pointer_traits primary template - // will deduce element_type of __normal_iterator<T*, C> as T* rather than T. - template<typename _Iterator, typename _Container> - [[__gnu__::__always_inline__]] _GLIBCXX_NODISCARD - constexpr auto - __to_address(const __gnu_cxx::__normal_iterator<_Iterator, - _Container>& __it) noexcept - -> decltype(std::__to_address(__it.base())) - { return std::__to_address(__it.base()); } -#endif - #if __cplusplus >= 201103L /** * @addtogroup iterators diff --git a/libstdc++-v3/include/debug/safe_iterator.h b/libstdc++-v3/include/debug/safe_iterator.h index d3e959b..983cbae 100644 --- a/libstdc++-v3/include/debug/safe_iterator.h +++ b/libstdc++-v3/include/debug/safe_iterator.h @@ -1161,23 +1161,6 @@ namespace __gnu_debug } // namespace __gnu_debug -#if __cplusplus >= 201103L && __cplusplus <= 201703L -namespace std _GLIBCXX_VISIBILITY(default) -{ -_GLIBCXX_BEGIN_NAMESPACE_VERSION - - template<typename _Iterator, typename _Container, typename _Sequence> - constexpr auto - __to_address(const __gnu_debug::_Safe_iterator< - __gnu_cxx::__normal_iterator<_Iterator, _Container>, - _Sequence>& __it) noexcept - -> decltype(std::__to_address(__it.base().base())) - { return std::__to_address(__it.base().base()); } - -_GLIBCXX_END_NAMESPACE_VERSION -} -#endif - #undef _GLIBCXX20_CONSTEXPR_NON_LITERAL_SCOPE_END #undef _GLIBCXX20_CONSTEXPR_NON_LITERAL_SCOPE_BEGIN #undef _GLIBCXX_DEBUG_VERIFY_DIST_OPERANDS diff --git a/libstdc++-v3/include/std/ranges b/libstdc++-v3/include/std/ranges index 5b45588..9f23372 100644 --- a/libstdc++-v3/include/std/ranges +++ b/libstdc++-v3/include/std/ranges @@ -3935,7 +3935,7 @@ namespace views::__adaptor operator() [[nodiscard]] (_Iter __i, iter_difference_t<_Iter> __n) const { if constexpr (contiguous_iterator<_Iter>) - return span(std::__to_address(__i), __n); + return span(std::to_address(__i), __n); else if constexpr (random_access_iterator<_Iter>) return subrange(__i, __i + __n); else diff --git a/libstdc++-v3/testsuite/24_iterators/normal_iterator/to_address.cc b/libstdc++-v3/testsuite/24_iterators/normal_iterator/to_address.cc deleted file mode 100644 index 6afc654..0000000 --- a/libstdc++-v3/testsuite/24_iterators/normal_iterator/to_address.cc +++ /dev/null @@ -1,19 +0,0 @@ -// { dg-do compile { target { c++11 } } } -#include <string> -#include <vector> -#include <memory> - -#include <testsuite_allocator.h> - -char* p __attribute__((unused)) - = std::__to_address(std::string("1").begin()); -const char* q __attribute__((unused)) - = std::__to_address(std::string("2").cbegin()); -int* r __attribute__((unused)) - = std::__to_address(std::vector<int>(1, 1).begin()); -const int* s __attribute__((unused)) - = std::__to_address(std::vector<int>(1, 1).cbegin()); -int* t __attribute__((unused)) - = std::__to_address(std::vector<int, __gnu_test::CustomPointerAlloc<int>>(1, 1).begin()); -const int* u __attribute__((unused)) - = std::__to_address(std::vector<int, __gnu_test::CustomPointerAlloc<int>>(1, 1).cbegin()); |