diff --git a/libstdc++-v3/include/bits/stl_iterator.h b/libstdc++-v3/include/bits/stl_iterator.h index 8afd6756613..6b915ec011c 100644 --- a/libstdc++-v3/include/bits/stl_iterator.h +++ b/libstdc++-v3/include/bits/stl_iterator.h @@ -1312,32 +1312,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #if __cplusplus >= 201103L - // Need to specialize pointer_traits because the primary template will - // deduce element_type of __normal_iterator as T* rather than T. + // Need to overload __to_address because the pointer_traits primary template + // will deduce element_type of __normal_iterator as T* rather than T. template - struct pointer_traits<__gnu_cxx::__normal_iterator<_Iterator, _Container>> - { - private: - using _Base = pointer_traits<_Iterator>; - - public: - using element_type = typename _Base::element_type; - using pointer = __gnu_cxx::__normal_iterator<_Iterator, _Container>; - using difference_type = typename _Base::difference_type; - - template - using rebind = __gnu_cxx::__normal_iterator<_Tp, _Container>; - - static pointer - pointer_to(element_type& __e) noexcept - { return pointer(_Base::pointer_to(__e)); } - -#if __cplusplus >= 202002L - static element_type* - to_address(pointer __p) noexcept - { return __p.base(); } -#endif - }; + 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()); } /** * @addtogroup iterators diff --git a/libstdc++-v3/include/debug/safe_iterator.h b/libstdc++-v3/include/debug/safe_iterator.h index 5584d06de5a..09e35f79067 100644 --- a/libstdc++-v3/include/debug/safe_iterator.h +++ b/libstdc++-v3/include/debug/safe_iterator.h @@ -1018,6 +1018,23 @@ namespace __gnu_debug #undef _GLIBCXX_DEBUG_VERIFY_EQ_OPERANDS #undef _GLIBCXX_DEBUG_VERIFY_OPERANDS +#if __cplusplus >= 201103L +namespace std _GLIBCXX_VISIBILITY(default) +{ +_GLIBCXX_BEGIN_NAMESPACE_VERSION + + template + constexpr auto + __to_address(const __gnu_debug::_Safe_iterator< + __gnu_cxx::__normal_iterator<_Iterator, _Container>, + _Sequence>& __it) noexcept + -> decltype(std::__to_address(__it.base())) + { return std::__to_address(__it.base()); } + +_GLIBCXX_END_NAMESPACE_VERSION +} +#endif + #include #endif diff --git a/libstdc++-v3/testsuite/24_iterators/normal_iterator/to_address.cc b/libstdc++-v3/testsuite/24_iterators/normal_iterator/to_address.cc index 510d627435f..433c803beb1 100644 --- a/libstdc++-v3/testsuite/24_iterators/normal_iterator/to_address.cc +++ b/libstdc++-v3/testsuite/24_iterators/normal_iterator/to_address.cc @@ -1,6 +1,9 @@ // { dg-do compile { target { c++11 } } } #include +#include #include char* p = std::__to_address(std::string("1").begin()); const char* q = std::__to_address(std::string("2").cbegin()); +int* r = std::__to_address(std::vector(1, 1).begin()); +const int* s = std::__to_address(std::vector(1, 1).cbegin());