diff mbox

Make vector::data() return type consistent in C++98

Message ID 20161024122531.GK2922@redhat.com
State Accepted
Commit 405def8d4667163a262f6c9fcb4a8f675dae4193
Headers show

Commit Message

Jonathan Wakely Oct. 24, 2016, 12:25 p.m. UTC
At https://gcc.gnu.org/ml/libstdc++/2016-08/msg00123.html I suggested
changing the non-standard return type of vector::data() in C++98 mode.
Nobody objected, so I'm making that change.

This removes a silent ABI incompatibility betwen C++98 mode and later
modes, for std::vector<T, A>::data() where A::pointer is not T*.

For most uses (where A is std::allocator, or A::pointer is T*) it
makes no difference.

	* include/bits/stl_vector.h (vector::_M_data_ptr, vector::data):
	Change return type of non-standard C++98 extension to match C++11.

Tested powerpc64le-linux, with -std=gnu++98 too, committed to trunk.
diff mbox

Patch

commit 5ff5b46535193b9732130ba20030647e1fbb7d35
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Sat Oct 22 12:49:11 2016 +0100

    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.

diff --git a/libstdc++-v3/include/bits/stl_vector.h b/libstdc++-v3/include/bits/stl_vector.h
index efc569b..697a73c 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<typename _Up>
 	_Up*
-	_M_data_ptr(_Up* __ptr) const
+	_M_data_ptr(_Up* __ptr) const _GLIBCXX_NOEXCEPT
 	{ return __ptr; }
 
+#if __cplusplus >= 201103L
       template<typename _Ptr>
 	typename std::pointer_traits<_Ptr>::element_type*
 	_M_data_ptr(_Ptr __ptr) const
 	{ return empty() ? nullptr : std::__addressof(*__ptr); }
 #else
-      template<typename _Ptr>
-	_Ptr
-	_M_data_ptr(_Ptr __ptr) const
+      template<typename _Up>
+	_Up*
+	_M_data_ptr(_Up* __ptr) _GLIBCXX_NOEXCEPT
 	{ return __ptr; }
+
+      template<typename _Ptr>
+	value_type*
+	_M_data_ptr(_Ptr __ptr)
+	{ return __ptr.operator->(); }
+
+      template<typename _Ptr>
+	const value_type*
+	_M_data_ptr(_Ptr __ptr) const
+	{ return __ptr.operator->(); }
 #endif
     };