From 431a9dda09087eb7345c451164a22e9ab6fe250e Mon Sep 17 00:00:00 2001 From: redi Date: Thu, 23 Aug 2018 10:51:52 +0000 Subject: [PATCH] Fix testsuite failures for __gnu_debug::string with old ABI The __gnu_debug string (mostly) implements the C++11 API, but when it wraps the old COW string many of the member functions in the base class have the wrong parameter types or return types. This makes the __gnu_debug::string type adapt itself to the base class API. This actually makes the debug string slightly more conforming than the underlying string type when using the old ABI. * include/bits/basic_string.h [_GLIBCXX_USE_CXX11_ABI] (basic_string::__const_iterator): Change access to protected. [!_GLIBCXX_USE_CXX11_ABI] (basic_string::__const_iterator): Define as typedef for iterator. * include/debug/string (__const_iterator): Use typedef from base. (insert(const_iterator, _CharT)) (replace(const_iterator, const_iterator, const basic_string&)) (replace(const_iterator, const_iterator, const _CharT*, size_type)) (replace(const_iterator, const_iterator, const CharT*)) (replace(const_iterator, const_iterator, size_type, _CharT)) (replace(const_iterator, const_iterator, _InputIter, _InputIter)) (replace(const_iterator, const_iterator, initializer_list<_CharT>)): Change const_iterator parameters to __const_iterator. (insert(iterator, size_type, _CharT)): Add C++98 overload. (insert(const_iterator, _InputIterator, _InputIterator)): Change const_iterator parameter to __const_iterator. [!_GLIBCXX_USE_CXX11_ABI]: Add workaround for incorrect return type of base's member function. (insert(const_iterator, size_type, _CharT)) [!_GLIBCXX_USE_CXX11_ABI]: Likewise. (insert(const_iterator, initializer_list<_CharT>)) [!_GLIBCXX_USE_CXX11_ABI]: Likewise. * testsuite/21_strings/basic_string/init-list.cc: Remove effective target directive. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@263808 138bc75d-0d04-0410-961f-82ee72b054a4 --- libstdc++-v3/ChangeLog | 25 ++++++++++ libstdc++-v3/include/bits/basic_string.h | 7 ++- libstdc++-v3/include/debug/string | 55 ++++++++++++++++++---- .../testsuite/21_strings/basic_string/init-list.cc | 1 - 4 files changed, 77 insertions(+), 11 deletions(-) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 25218bf4fcf..54b8a2f1782 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,5 +1,30 @@ 2018-08-23 Jonathan Wakely + * include/bits/basic_string.h [_GLIBCXX_USE_CXX11_ABI] + (basic_string::__const_iterator): Change access to protected. + [!_GLIBCXX_USE_CXX11_ABI] (basic_string::__const_iterator): Define + as typedef for iterator. + * include/debug/string (__const_iterator): Use typedef from base. + (insert(const_iterator, _CharT)) + (replace(const_iterator, const_iterator, const basic_string&)) + (replace(const_iterator, const_iterator, const _CharT*, size_type)) + (replace(const_iterator, const_iterator, const CharT*)) + (replace(const_iterator, const_iterator, size_type, _CharT)) + (replace(const_iterator, const_iterator, _InputIter, _InputIter)) + (replace(const_iterator, const_iterator, initializer_list<_CharT>)): + Change const_iterator parameters to __const_iterator. + (insert(iterator, size_type, _CharT)): Add C++98 overload. + (insert(const_iterator, _InputIterator, _InputIterator)): Change + const_iterator parameter to __const_iterator. + [!_GLIBCXX_USE_CXX11_ABI]: Add workaround for incorrect return type + of base's member function. + (insert(const_iterator, size_type, _CharT)) [!_GLIBCXX_USE_CXX11_ABI]: + Likewise. + (insert(const_iterator, initializer_list<_CharT>)) + [!_GLIBCXX_USE_CXX11_ABI]: Likewise. + * testsuite/21_strings/basic_string/init-list.cc: Remove effective + target directive. + * testsuite/20_util/reference_wrapper/lwg2993.cc: Fix C++11 test to not use C++14 feature. * testsuite/23_containers/list/68222_neg.cc: Likewise. diff --git a/libstdc++-v3/include/bits/basic_string.h b/libstdc++-v3/include/bits/basic_string.h index c9463989ddc..ba94b51f616 100644 --- a/libstdc++-v3/include/bits/basic_string.h +++ b/libstdc++-v3/include/bits/basic_string.h @@ -100,7 +100,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 /// Value returned by various member functions when they fail. static const size_type npos = static_cast(-1); - private: + protected: // type used for positions in insert, erase etc. #if __cplusplus < 201103L typedef iterator __const_iterator; @@ -108,6 +108,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 typedef const_iterator __const_iterator; #endif + private: #if __cplusplus > 201402L // A helper type for avoiding boiler-plate. typedef basic_string_view<_CharT, _Traits> __sv_type; @@ -3119,6 +3120,10 @@ _GLIBCXX_END_NAMESPACE_CXX11 typedef std::reverse_iterator const_reverse_iterator; typedef std::reverse_iterator reverse_iterator; + protected: + // type used for positions in insert, erase etc. + typedef iterator __const_iterator; + private: // _Rep: string representation // Invariants: diff --git a/libstdc++-v3/include/debug/string b/libstdc++-v3/include/debug/string index 1883cac2fbb..d330bfd5a3f 100644 --- a/libstdc++-v3/include/debug/string +++ b/libstdc++-v3/include/debug/string @@ -97,6 +97,10 @@ namespace __gnu_debug template friend class ::__gnu_debug::_Safe_iterator; + // type used for positions in insert, erase etc. + typedef __gnu_debug::_Safe_iterator< + typename _Base::__const_iterator, basic_string> __const_iterator; + public: // types: typedef _Traits traits_type; @@ -589,7 +593,7 @@ namespace __gnu_debug } iterator - insert(const_iterator __p, _CharT __c) + insert(__const_iterator __p, _CharT __c) { __glibcxx_check_insert(__p); typename _Base::iterator __res = _Base::insert(__p.base(), __c); @@ -597,29 +601,51 @@ namespace __gnu_debug return iterator(__res, this); } +#if __cplusplus >= 201103L iterator insert(const_iterator __p, size_type __n, _CharT __c) { __glibcxx_check_insert(__p); +#if _GLIBCXX_USE_CXX11_ABI typename _Base::iterator __res = _Base::insert(__p.base(), __n, __c); +#else + const size_type __offset = __p.base() - _Base::cbegin(); + _Base::insert(_Base::begin() + __offset, __n, __c); + typename _Base::iterator __res = _Base::begin() + __offset; +#endif this->_M_invalidate_all(); return iterator(__res, this); } +#else + void + insert(iterator __p, size_type __n, _CharT __c) + { + __glibcxx_check_insert(__p); + _Base::insert(__p.base(), __n, __c); + this->_M_invalidate_all(); + } +#endif template iterator - insert(const_iterator __p, + insert(__const_iterator __p, _InputIterator __first, _InputIterator __last) { typename __gnu_debug::_Distance_traits<_InputIterator>::__type __dist; __glibcxx_check_insert_range(__p, __first, __last, __dist); typename _Base::iterator __res; +#if _GLIBCXX_USE_CXX11_ABI if (__dist.second >= __dp_sign) __res = _Base::insert(__p.base(), __gnu_debug::__unsafe(__first), __gnu_debug::__unsafe(__last)); else __res = _Base::insert(__p.base(), __first, __last); +#else + const size_type __offset = __p.base() - _Base::cbegin(); + _Base::insert(__p.base(), __first, __last); + __res = _Base::begin() + __offset; +#endif this->_M_invalidate_all(); return iterator(__res, this); } @@ -629,7 +655,13 @@ namespace __gnu_debug insert(const_iterator __p, std::initializer_list<_CharT> __l) { __glibcxx_check_insert(__p); +#if _GLIBCXX_USE_CXX11_ABI const auto __res = _Base::insert(__p.base(), __l); +#else + const size_type __offset = __p.base() - _Base::cbegin(); + _Base::insert(_Base::begin() + __offset, __l); + auto __res = _Base::begin() + __offset; +#endif this->_M_invalidate_all(); return iterator(__res, this); } @@ -719,7 +751,8 @@ namespace __gnu_debug } basic_string& - replace(iterator __i1, iterator __i2, const basic_string& __str) + replace(__const_iterator __i1, __const_iterator __i2, + const basic_string& __str) { __glibcxx_check_erase_range(__i1, __i2); _Base::replace(__i1.base(), __i2.base(), __str); @@ -728,7 +761,8 @@ namespace __gnu_debug } basic_string& - replace(iterator __i1, iterator __i2, const _CharT* __s, size_type __n) + replace(__const_iterator __i1, __const_iterator __i2, + const _CharT* __s, size_type __n) { __glibcxx_check_erase_range(__i1, __i2); __glibcxx_check_string_len(__s, __n); @@ -738,7 +772,8 @@ namespace __gnu_debug } basic_string& - replace(iterator __i1, iterator __i2, const _CharT* __s) + replace(__const_iterator __i1, __const_iterator __i2, + const _CharT* __s) { __glibcxx_check_erase_range(__i1, __i2); __glibcxx_check_string(__s); @@ -748,7 +783,8 @@ namespace __gnu_debug } basic_string& - replace(iterator __i1, iterator __i2, size_type __n, _CharT __c) + replace(__const_iterator __i1, __const_iterator __i2, + size_type __n, _CharT __c) { __glibcxx_check_erase_range(__i1, __i2); _Base::replace(__i1.base(), __i2.base(), __n, __c); @@ -758,7 +794,7 @@ namespace __gnu_debug template basic_string& - replace(iterator __i1, iterator __i2, + replace(__const_iterator __i1, __const_iterator __i2, _InputIterator __j1, _InputIterator __j2) { __glibcxx_check_erase_range(__i1, __i2); @@ -778,8 +814,9 @@ namespace __gnu_debug } #if __cplusplus >= 201103L - basic_string& replace(iterator __i1, iterator __i2, - std::initializer_list<_CharT> __l) + basic_string& + replace(__const_iterator __i1, __const_iterator __i2, + std::initializer_list<_CharT> __l) { __glibcxx_check_erase_range(__i1, __i2); _Base::replace(__i1.base(), __i2.base(), __l); diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/init-list.cc b/libstdc++-v3/testsuite/21_strings/basic_string/init-list.cc index 20a392c40fc..aa7754821b9 100644 --- a/libstdc++-v3/testsuite/21_strings/basic_string/init-list.cc +++ b/libstdc++-v3/testsuite/21_strings/basic_string/init-list.cc @@ -17,7 +17,6 @@ // // { dg-do run { target c++11 } } -// { dg-require-effective-target cxx11-abi } #include -- 2.11.4.GIT