aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3/include/debug
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2018-08-23 11:51:52 +0100
committerJonathan Wakely <redi@gcc.gnu.org>2018-08-23 11:51:52 +0100
commit3eb1eda1c8a9e77cdea79e796a331f265b83e2df (patch)
treebeb0ffd40e97fd63602b230696bd34a317f99c1b /libstdc++-v3/include/debug
parent832c74d935917263bb7f9852230bb39fd47584cc (diff)
downloadgcc-3eb1eda1c8a9e77cdea79e796a331f265b83e2df.zip
gcc-3eb1eda1c8a9e77cdea79e796a331f265b83e2df.tar.gz
gcc-3eb1eda1c8a9e77cdea79e796a331f265b83e2df.tar.bz2
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. From-SVN: r263808
Diffstat (limited to 'libstdc++-v3/include/debug')
-rw-r--r--libstdc++-v3/include/debug/string55
1 files changed, 46 insertions, 9 deletions
diff --git a/libstdc++-v3/include/debug/string b/libstdc++-v3/include/debug/string
index 1883cac..d330bfd 100644
--- a/libstdc++-v3/include/debug/string
+++ b/libstdc++-v3/include/debug/string
@@ -97,6 +97,10 @@ namespace __gnu_debug
template<typename _ItT, typename _SeqT, typename _CatT>
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<typename _InputIterator>
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<typename _InputIterator>
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);