This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Skip tests that depend on the cxx11 std::string


On 23/08/18 10:03 +0100, Jonathan Wakely wrote:
On 23/08/18 09:24 +0100, Jonathan Wakely wrote:
--- a/libstdc++-v3/testsuite/21_strings/basic_string/init-list.cc
+++ b/libstdc++-v3/testsuite/21_strings/basic_string/init-list.cc
@@ -17,6 +17,7 @@
//

// { dg-do run { target c++11 } }
+// { dg-require-effective-target cxx11-abi }

Actually I shouldn't have added it here. It only depends on the new
string when compiled with _GLIBCXX_DEBUG, and that should be fixed in
__gnu_debug::string not by skipping the test.

Like so.

Tested x86_64-linux, committed to trunk.


commit eaf0a58cf22a0164001560efc5f7f966bf8ac6ca
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Thu Aug 23 11:26:05 2018 +0100

    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.

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<size_type>(-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_iterator>	const_reverse_iterator;
       typedef std::reverse_iterator<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<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);
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 <testsuite_hooks.h>
 

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]