From 405def8d4667163a262f6c9fcb4a8f675dae4193 Mon Sep 17 00:00:00 2001 From: Jonathan Wakely Date: Mon, 24 Oct 2016 13:25:28 +0100 Subject: [PATCH] Make vector::data() return type consistent in C++98 * include/bits/stl_vector.h (vector::_M_data_ptr, vector::data): Change return type of non-standard C++98 extension to match C++11. From-SVN: r241475 --- libstdc++-v3/ChangeLog | 5 +++++ libstdc++-v3/include/bits/stl_vector.h | 26 ++++++++++++++------------ 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index c344441ecd0..7d0a0022d62 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,8 @@ +2016-10-24 Jonathan Wakely + + * include/bits/stl_vector.h (vector::_M_data_ptr, vector::data): + Change return type of non-standard C++98 extension to match C++11. + 2016-10-22 François Dumont * include/bits/c++config (_GLIBCXX_BEGIN_NAMESPACE_ALGO) diff --git a/libstdc++-v3/include/bits/stl_vector.h b/libstdc++-v3/include/bits/stl_vector.h index efc569b9c84..697a73c179f 100644 --- a/libstdc++-v3/include/bits/stl_vector.h +++ b/libstdc++-v3/include/bits/stl_vector.h @@ -914,19 +914,11 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * Returns a pointer such that [data(), data() + size()) is a valid * range. For a non-empty %vector, data() == &front(). */ -#if __cplusplus >= 201103L _Tp* -#else - pointer -#endif data() _GLIBCXX_NOEXCEPT { return _M_data_ptr(this->_M_impl._M_start); } -#if __cplusplus >= 201103L const _Tp* -#else - const_pointer -#endif data() const _GLIBCXX_NOEXCEPT { return _M_data_ptr(this->_M_impl._M_start); } @@ -1558,21 +1550,31 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER } #endif -#if __cplusplus >= 201103L template _Up* - _M_data_ptr(_Up* __ptr) const + _M_data_ptr(_Up* __ptr) const _GLIBCXX_NOEXCEPT { return __ptr; } +#if __cplusplus >= 201103L template typename std::pointer_traits<_Ptr>::element_type* _M_data_ptr(_Ptr __ptr) const { return empty() ? nullptr : std::__addressof(*__ptr); } #else + template + _Up* + _M_data_ptr(_Up* __ptr) _GLIBCXX_NOEXCEPT + { return __ptr; } + + template + value_type* + _M_data_ptr(_Ptr __ptr) + { return __ptr.operator->(); } + template - _Ptr + const value_type* _M_data_ptr(_Ptr __ptr) const - { return __ptr; } + { return __ptr.operator->(); } #endif }; -- 2.30.2