Following your feedback here is the simplified version. I grouped it with the patch I submitted before.

On 19/03/21 8:41 pm, Jonathan Wakely wrote:
On 16/03/21 21:55 +0100, François Dumont via Libstdc++ wrote:
Following:

https://gcc.gnu.org/pipermail/libstdc++/2021-March/052158.html

Here is the patch to complete __gnu_debug::basic_string support. Contrarily to what I thought code in std::basic_string to generate a basic_string_view works just fine for __gnu_debug::basic_string.

    libstdc++: [_GLIBCXX_DEBUG] Add __gnu_debug u8string/u16string/u32string

    Complete __gnu_debug::basic_string support so that it can be used as a
    transparent replacement of std::basic_string.

    libstdc++-v3/ChangeLog:

            * include/debug/string
            (basic_string(const _CharT*, const _Allocator&)): Remove assign call.             (basic_string<>::insert(const_iterator, _InputIte, _InputIte)): Try to
            remove iterator debug layer even if !_GLIBCXX_USE_CXX11_ABI.
            [_GLIBCXX_USE_CHAR8_T] (__gnu_debug::u8string): New.
            (__gnu_debug::u16string, __gnu_debug::u32string): New.
[!_GLIBCXX_COMPATIBILITY_CXX0X](std::hash<__gnu_debug::string>): New.
[!_GLIBCXX_COMPATIBILITY_CXX0X][_GLIBCXX_USE_WCHAR_T](std::hash<__gnu_debug::wstring>): New.
[_GLIBCXX_USE_CHAR8_T](std::hash<__gnu_debug::u8string>): New.
            (std::hash<__gnu_debug::u16string>): New.
            (std::hash<__gnu_debug::u32string>): New.
            * testsuite/21_strings/basic_string/hash/hash_char8_t.cc: Adapt for
            __gnu_debug basic_string.

Tested under Linux x86_64.

Ok to commit ?

François


diff --git a/libstdc++-v3/include/debug/string b/libstdc++-v3/include/debug/string
index d6eb5280ade..dec23f6277b 100644
--- a/libstdc++-v3/include/debug/string
+++ b/libstdc++-v3/include/debug/string
@@ -41,6 +41,14 @@
    __gnu_debug::_Error_formatter::_S_at(_File, _Line, _Func)        \
      ._M_message(#_Cond)._M_error()

+#if _GLIBCXX_USE_CXX11_ABI && __cplusplus >= 201103
+# define _GLIBCXX_CPP11_AND_CXX11_ABI 1
+# define _GLIBCXX_CPP11_AND_CXX11_ABI_ONLY(Statement) Statement

This takes an expression, not a statement.

I've been inspired by _GLIBCXX_DEBUG_ONLY


I think it would be better to use more descriptive names for these:

# define _GLIBCXX_INSERT_RETURNS_ITERATOR 1
# define _GLIBCXX_INSERT_RETURNS_ITERATOR_ONLY(expr) expr

(And don't forget to change the #undef lines too).

+#if __cplusplus >= 201103L
+
+namespace std _GLIBCXX_VISIBILITY(default)
+{
+_GLIBCXX_BEGIN_NAMESPACE_VERSION
+
+  // DR 1182.
+
+#ifndef _GLIBCXX_COMPATIBILITY_CXX0X
+  /// std::hash specialization for string.
+  template<>
+    struct hash<__gnu_debug::string>
+    : public __hash_base<size_t, __gnu_debug::string>

I think we could just define on partial specialization that works for
all cases:

Yes, sounds better. But I relied on std::__hash_base which gives directly the correct definition.


Why only make this change for the char8_t version? Why not test
hash<__gnu_debug::string> as well?

This file also test std::string and so also __gnu_debug::string.

    libstdc++: Fix and complete __gnu_debug::basic_string implementation

    Fix and complete __gnu_debug::basic_string so that it can be used as a transparent
    replacement of std::basic_string.

    libstdc++-v3/ChangeLog:

            * include/debug/string
            (basic_string(const _CharT*, const _Allocator&)): Remove assign call.             (basic_string<>::insert(const_iterator, _InputIte, _InputIte)): Try to
            remove iterator debug layer even if !_GLIBCXX_USE_CXX11_ABI.
            [_GLIBCXX_USE_CHAR8_T] (__gnu_debug::u8string): New.
            (__gnu_debug::u16string, __gnu_debug::u32string): New.
            (std::hash<__gnu_debug::basic_string<>>): New partial specialization.
(std::__is_fast_hash<__gnu_debug::basic_string<>>): Likewise.
            (basic_string(const basic_string&, const _Alloc&)): Define even if !_GLIBCXX_USE_CXX11_ABI.             (basic_string(basic_string&&, const _Alloc&)): Likewise and add noexcept qualification.
            (basic_string<>::erase): Adapt to take __const_iterator.
            * testsuite/21_strings/basic_string/hash/debug.cc: New test.
            * testsuite/21_strings/basic_string/hash/debug_char8_t.cc: New test.             * testsuite/21_strings/basic_string/requirements/citerators.cc: Adapt to test __gnu_debug::string
            when _GLIBCXX_DEBUG is defined.
            * testsuite/21_strings/basic_string/requirements/dr438/constructor.cc: Likewise.             * testsuite/21_strings/basic_string/requirements/exception/basic.cc: Likewise.             * testsuite/21_strings/basic_string/requirements/exception/generation_prohibited.cc: Likewise.             * testsuite/21_strings/basic_string/requirements/exception/propagation_consistent.cc: Likewise.             * testsuite/21_strings/basic_string/requirements/explicit_instantiation/char/1.cc: Likewise.             * testsuite/21_strings/basic_string/requirements/explicit_instantiation/char16_t/1.cc: Likewise.             * testsuite/21_strings/basic_string/requirements/explicit_instantiation/char32_t/1.cc: Likewise.             * testsuite/21_strings/basic_string/requirements/explicit_instantiation/char8_t/1.cc: Likewise.             * testsuite/21_strings/basic_string/requirements/explicit_instantiation/wchar_t/1.cc: Likewise.             * testsuite/21_strings/basic_string/requirements/typedefs.cc: Likewise.             * testsuite/util/exception/safety.h (erase_base<__gnu_debug::basic_string<>>): New partial
            specialization.
            (insert_base<__gnu_debug::basic_string<>>): Likewise.
            * testsuite/util/testsuite_container_traits.h (traits<__gnu_debug::basic_string<>>): Likewise.


Tested under Linux x86_64.

Ok to commit ?

François

diff --git a/libstdc++-v3/include/debug/string b/libstdc++-v3/include/debug/string
index 172179530aa..f665c759557 100644
--- a/libstdc++-v3/include/debug/string
+++ b/libstdc++-v3/include/debug/string
@@ -41,6 +41,14 @@
     __gnu_debug::_Error_formatter::_S_at(_File, _Line, _Func)		\
       ._M_message(#_Cond)._M_error()
 
+#if _GLIBCXX_USE_CXX11_ABI && __cplusplus >= 201103
+# define _GLIBCXX_INSERT_RETURNS_ITERATOR 1
+# define _GLIBCXX_INSERT_RETURNS_ITERATOR_ONLY(expr) expr
+#else
+# define _GLIBCXX_INSERT_RETURNS_ITERATOR 0
+# define _GLIBCXX_INSERT_RETURNS_ITERATOR_ONLY(expr)
+#endif
+
 namespace __gnu_debug
 {
   /** Checks that __s is non-NULL or __n == 0, and then returns __s. */
@@ -123,21 +131,21 @@ namespace __gnu_debug
 
       using _Base::npos;
 
-      basic_string()
-	_GLIBCXX_NOEXCEPT_IF(std::is_nothrow_default_constructible<_Base>::value)
-	: _Base() { }
-
       // 21.3.1 construct/copy/destroy:
+
       explicit
       basic_string(const _Allocator& __a) _GLIBCXX_NOEXCEPT
       : _Base(__a) { }
 
 #if __cplusplus < 201103L
+      basic_string() : _Base() { }
+
       basic_string(const basic_string& __str)
       : _Base(__str) { }
 
       ~basic_string() { }
 #else
+      basic_string() = default;
       basic_string(const basic_string&) = default;
       basic_string(basic_string&&) = default;
 
@@ -146,13 +154,15 @@ namespace __gnu_debug
       : _Base(__l, __a)
       { }
 
-#if _GLIBCXX_USE_CXX11_ABI
       basic_string(const basic_string& __s, const _Allocator& __a)
       : _Base(__s, __a) { }
 
       basic_string(basic_string&& __s, const _Allocator& __a)
-      : _Base(std::move(__s), __a) { }
-#endif
+      noexcept( noexcept(
+	_Base(std::declval<_Base>()), std::declval<const _Allocator&>()) )
+      : _Safe(std::move(__s._M_safe()), __a),
+	_Base(std::move(__s._M_base()), __a)
+      { }
 
       ~basic_string() = default;
 
@@ -178,7 +188,7 @@ namespace __gnu_debug
 
       basic_string(const _CharT* __s, const _Allocator& __a = _Allocator())
       : _Base(__glibcxx_check_string_constructor(__s), __a)
-      { this->assign(__s); }
+      { }
 
       basic_string(size_type __n, _CharT __c,
 		   const _Allocator& __a = _Allocator())
@@ -635,15 +645,22 @@ namespace __gnu_debug
 	  __glibcxx_check_insert_range(__p, __first, __last, __dist);
 
 	  typename _Base::iterator __res;
-#if _GLIBCXX_USE_CXX11_ABI && __cplusplus >= 201103
+#if ! _GLIBCXX_INSERT_RETURNS_ITERATOR
+	  const size_type __offset = __p.base() - _Base::begin();
+#endif
 	  if (__dist.second >= __dp_sign)
-	    __res = _Base::insert(__p.base(), __gnu_debug::__unsafe(__first),
-				  __gnu_debug::__unsafe(__last));
+	    {
+	      _GLIBCXX_INSERT_RETURNS_ITERATOR_ONLY(__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::begin();
-	  _Base::insert(__p.base(), __first, __last);
+	    {
+	      _GLIBCXX_INSERT_RETURNS_ITERATOR_ONLY(__res =)
+		_Base::insert(__p.base(), __first, __last);
+	    }
+
+#if ! _GLIBCXX_INSERT_RETURNS_ITERATOR
 	  __res = _Base::begin() + __offset;
 #endif
 	  this->_M_invalidate_all();
@@ -676,7 +693,7 @@ namespace __gnu_debug
       }
 
       iterator
-      erase(iterator __position)
+      erase(__const_iterator __position)
       {
 	__glibcxx_check_erase(__position);
 	typename _Base::iterator __res = _Base::erase(__position.base());
@@ -685,7 +702,7 @@ namespace __gnu_debug
       }
 
       iterator
-      erase(iterator __first, iterator __last)
+      erase(__const_iterator __first, __const_iterator __last)
       {
 	// _GLIBCXX_RESOLVE_LIB_DEFECTS
 	// 151. can't currently clear() empty container
@@ -1285,6 +1302,19 @@ namespace __gnu_debug
   typedef basic_string<wchar_t> wstring;
 #endif
 
+#ifdef _GLIBCXX_USE_CHAR8_T
+  /// A string of @c char8_t
+  typedef basic_string<char8_t> u8string;
+#endif
+
+#if __cplusplus >= 201103L
+  /// A string of @c char16_t
+  typedef basic_string<char16_t> u16string;
+
+  /// A string of @c char32_t
+  typedef basic_string<char32_t> u32string;
+#endif
+
   template<typename _CharT, typename _Traits, typename _Allocator>
     struct _Insert_range_from_self_is_safe<
       __gnu_debug::basic_string<_CharT, _Traits, _Allocator> >
@@ -1292,4 +1322,31 @@ namespace __gnu_debug
 
 } // namespace __gnu_debug
 
+#if __cplusplus >= 201103L
+namespace std _GLIBCXX_VISIBILITY(default)
+{
+_GLIBCXX_BEGIN_NAMESPACE_VERSION
+
+  /// std::hash specialization for __gnu_debug::basic_string.
+  template<typename _CharT>
+    struct hash<__gnu_debug::basic_string<_CharT>>
+    : public __hash_base<size_t, __gnu_debug::basic_string<_CharT>>
+    {
+      size_t
+      operator()(const __gnu_debug::basic_string<_CharT>& __s) const noexcept
+      { return std::hash<std::basic_string<_CharT>>()(__s); }
+    };
+
+  template<typename _CharT>
+    struct __is_fast_hash<hash<__gnu_debug::basic_string<_CharT>>>
+    : std::false_type
+    { };
+
+_GLIBCXX_END_NAMESPACE_VERSION
+}
+#endif /* C++11 */
+
+#undef _GLIBCXX_INSERT_RETURNS_ITERATOR
+#undef _GLIBCXX_INSERT_RETURNS_ITERATOR_ONLY
+
 #endif
diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/hash/debug.cc b/libstdc++-v3/testsuite/21_strings/basic_string/hash/debug.cc
new file mode 100644
index 00000000000..84c989590b7
--- /dev/null
+++ b/libstdc++-v3/testsuite/21_strings/basic_string/hash/debug.cc
@@ -0,0 +1,53 @@
+// Copyright (C) 2021 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-std=gnu++17" }
+// { dg-do run { target c++17 } }
+
+#include <debug/string>
+#include <memory_resource>
+#include <testsuite_hooks.h>
+
+// C++17 24.3.5 [basic.string.hash]
+// If S is one of these string types, SV is the corresponding string view type,
+// and s is an object of type S, then hash<S>()(s) == hash<SV>()(SV(s)).
+
+template<typename S>
+  bool
+  test(const S& s)
+  {
+    using std::hash;
+    using SV = std::basic_string_view<typename S::value_type>;
+    return hash<S>()(s) == hash<SV>()(SV(s));
+  }
+
+void
+test01()
+{
+  VERIFY( test(__gnu_debug::string("a narrow string")) );
+  VERIFY( test(__gnu_debug::u16string(u"a utf-16 string")) );
+  VERIFY( test(__gnu_debug::u32string(U"a utf-32 string")) );
+#if _GLIBCXX_USE_WCHAR_T
+  VERIFY( test(__gnu_debug::wstring(L"a wide string")) );
+#endif
+}
+
+int
+main()
+{
+  test01();
+}
diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/hash/debug_char8_t.cc b/libstdc++-v3/testsuite/21_strings/basic_string/hash/debug_char8_t.cc
new file mode 100644
index 00000000000..b0c1eac2df3
--- /dev/null
+++ b/libstdc++-v3/testsuite/21_strings/basic_string/hash/debug_char8_t.cc
@@ -0,0 +1,59 @@
+// Copyright (C) 2019-2021 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-std=gnu++2a" }
+// { dg-do run { target c++2a } }
+
+#include <debug/string>
+#include <memory_resource>
+#include <testsuite_hooks.h>
+
+// C++2a N4810 21.3.5 [basic.string.hash]
+// If S is one of these string types, SV is the corresponding string view type,
+// and s is an object of type S, then hash<S>()(s) == hash<SV>()(SV(s)).
+
+template<typename S>
+  bool
+  test(const S& s)
+  {
+    using std::hash;
+    using SV = std::basic_string_view<typename S::value_type>;
+    return hash<S>()(s) == hash<SV>()(SV(s));
+  }
+
+void
+test01()
+{
+  VERIFY( test(__gnu_debug::string("a narrow string")) );
+  VERIFY( test(__gnu_debug::u8string(u8"a utf-8 string")) );
+}
+
+void
+test02()
+{
+  using std::hash;
+  __gnu_debug::string native("a string, a string, my stringdom for a string");
+  __gnu_debug::u8string utf8(u8"a string, a string, my stringdom for a string");
+  VERIFY( hash<__gnu_debug::string>()(native) == hash<__gnu_debug::u8string>()(utf8) );
+}
+
+int
+main()
+{
+  test01();
+  test02();
+}
diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/requirements/citerators.cc b/libstdc++-v3/testsuite/21_strings/basic_string/requirements/citerators.cc
index 99bf5726dcc..69d4a8d0e51 100644
--- a/libstdc++-v3/testsuite/21_strings/basic_string/requirements/citerators.cc
+++ b/libstdc++-v3/testsuite/21_strings/basic_string/requirements/citerators.cc
@@ -18,14 +18,21 @@
 // with this library; see the file COPYING3.  If not see
 // <http://www.gnu.org/licenses/>.
 
-#include <string>
 #include <testsuite_containers.h>
 
+#ifdef _GLIBCXX_DEBUG
+# include <debug/string>
+using namespace __gnu_debug;
+#else
+# include <string>
+using namespace std;
+#endif
+
 int main()
 {
-  __gnu_test::citerator<std::string> test1;
+  __gnu_test::citerator<string> test1;
 #ifdef _GLIBCXX_USE_WCHAR_T
-  __gnu_test::citerator<std::wstring> test2;
+  __gnu_test::citerator<wstring> test2;
 #endif
   return 0;
 }
diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/requirements/dr438/constructor.cc b/libstdc++-v3/testsuite/21_strings/basic_string/requirements/dr438/constructor.cc
index 82d42ebb6a6..104fd653642 100644
--- a/libstdc++-v3/testsuite/21_strings/basic_string/requirements/dr438/constructor.cc
+++ b/libstdc++-v3/testsuite/21_strings/basic_string/requirements/dr438/constructor.cc
@@ -19,9 +19,17 @@
 
 // { dg-do compile }
 
-#include <string>
+#ifdef _GLIBCXX_DEBUG
+# include <debug/string>
+
+using namespace __gnu_debug;
+#else
+# include <string>
+
+using namespace std;
+#endif
 
 void f()
 {
-  std::string s(10, 1);
+  string s(10, 1);
 }
diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/requirements/exception/basic.cc b/libstdc++-v3/testsuite/21_strings/basic_string/requirements/exception/basic.cc
index 2b6e27432e8..f40dda2b5bc 100644
--- a/libstdc++-v3/testsuite/21_strings/basic_string/requirements/exception/basic.cc
+++ b/libstdc++-v3/testsuite/21_strings/basic_string/requirements/exception/basic.cc
@@ -20,9 +20,16 @@
 // with this library; see the file COPYING3.  If not see
 // <http://www.gnu.org/licenses/>.
 
-#include <string>
 #include <exception/safety.h>
 
+#ifdef _GLIBCXX_DEBUG
+# include <debug/string>
+using namespace __gnu_debug;
+#else
+# include <string>
+using namespace std;
+#endif
+
 void
 value()
 {
@@ -31,7 +38,7 @@ value()
   typedef char value_type;
   typedef __gnu_cxx::throw_allocator_limit<value_type> allocator_type;
   typedef std::char_traits<value_type> traits_type;
-  typedef std::basic_string<value_type, traits_type, allocator_type> test_type;
+  typedef basic_string<value_type, traits_type, allocator_type> test_type;
   __gnu_test::basic_safety<test_type> test;
 }
 
diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/requirements/exception/generation_prohibited.cc b/libstdc++-v3/testsuite/21_strings/basic_string/requirements/exception/generation_prohibited.cc
index 07d2a2e2074..dc9bdb298ae 100644
--- a/libstdc++-v3/testsuite/21_strings/basic_string/requirements/exception/generation_prohibited.cc
+++ b/libstdc++-v3/testsuite/21_strings/basic_string/requirements/exception/generation_prohibited.cc
@@ -20,16 +20,23 @@
 // with this library; see the file COPYING3.  If not see
 // <http://www.gnu.org/licenses/>.
 
-#include <string>
 #include <exception/safety.h>
 
+#ifdef _GLIBCXX_DEBUG
+# include <debug/string>
+using namespace __gnu_debug;
+#else
+# include <string>
+using namespace std;
+#endif
+
 void
 char_allocator()
 {
   typedef char value_type;
   typedef __gnu_cxx::throw_allocator_random<value_type> allocator_type;
   typedef std::char_traits<value_type> traits_type;
-  typedef std::basic_string<value_type, traits_type, allocator_type> test_type;
+  typedef basic_string<value_type, traits_type, allocator_type> test_type;
   __gnu_test::generation_prohibited<test_type> test;
 }
 
@@ -39,7 +46,7 @@ wchar_allocator()
   typedef wchar_t value_type;
   typedef __gnu_cxx::throw_allocator_random<value_type> allocator_type;
   typedef std::char_traits<value_type> traits_type;
-  typedef std::basic_string<value_type, traits_type, allocator_type> test_type;
+  typedef basic_string<value_type, traits_type, allocator_type> test_type;
   __gnu_test::generation_prohibited<test_type> test;
 }
 
diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/requirements/exception/propagation_consistent.cc b/libstdc++-v3/testsuite/21_strings/basic_string/requirements/exception/propagation_consistent.cc
index ce99dab915e..818c487c9c9 100644
--- a/libstdc++-v3/testsuite/21_strings/basic_string/requirements/exception/propagation_consistent.cc
+++ b/libstdc++-v3/testsuite/21_strings/basic_string/requirements/exception/propagation_consistent.cc
@@ -20,9 +20,16 @@
 // with this library; see the file COPYING3.  If not see
 // <http://www.gnu.org/licenses/>.
 
-#include <string>
 #include <exception/safety.h>
 
+#ifdef _GLIBCXX_DEBUG
+# include <debug/string>
+using namespace __gnu_debug;
+#else
+# include <string>
+using namespace std;
+#endif
+
 void
 value()
 {
@@ -31,7 +38,7 @@ value()
   typedef char value_type;
   typedef __gnu_cxx::throw_allocator_limit<value_type> allocator_type;
   typedef std::char_traits<value_type> traits_type;
-  typedef std::basic_string<value_type, traits_type, allocator_type> test_type;
+  typedef basic_string<value_type, traits_type, allocator_type> test_type;
   __gnu_test::propagation_consistent<test_type> test;
 }
 
diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/requirements/explicit_instantiation/char/1.cc b/libstdc++-v3/testsuite/21_strings/basic_string/requirements/explicit_instantiation/char/1.cc
index 275354c1f4c..6910933253a 100644
--- a/libstdc++-v3/testsuite/21_strings/basic_string/requirements/explicit_instantiation/char/1.cc
+++ b/libstdc++-v3/testsuite/21_strings/basic_string/requirements/explicit_instantiation/char/1.cc
@@ -17,6 +17,12 @@
 // along with this library; see the file COPYING3.  If not see
 // <http://www.gnu.org/licenses/>.
 
-#include <string>
+#ifdef _GLIBCXX_DEBUG
+# include <debug/string>
+using namespace __gnu_debug;
+#else
+# include <string>
+using namespace std;
+#endif
 
-template class std::basic_string<char>;
+template class basic_string<char>;
diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/requirements/explicit_instantiation/char16_t/1.cc b/libstdc++-v3/testsuite/21_strings/basic_string/requirements/explicit_instantiation/char16_t/1.cc
index 2b5139de533..aadb9ef580c 100644
--- a/libstdc++-v3/testsuite/21_strings/basic_string/requirements/explicit_instantiation/char16_t/1.cc
+++ b/libstdc++-v3/testsuite/21_strings/basic_string/requirements/explicit_instantiation/char16_t/1.cc
@@ -17,6 +17,12 @@
 // along with this library; see the file COPYING3.  If not see
 // <http://www.gnu.org/licenses/>.
 
-#include <string>
+#ifdef _GLIBCXX_DEBUG
+# include <debug/string>
+using namespace __gnu_debug;
+#else
+# include <string>
+using namespace std;
+#endif
 
-template class std::basic_string<char16_t>;
+template class basic_string<char16_t>;
diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/requirements/explicit_instantiation/char32_t/1.cc b/libstdc++-v3/testsuite/21_strings/basic_string/requirements/explicit_instantiation/char32_t/1.cc
index 0fa685e9094..62760f7180f 100644
--- a/libstdc++-v3/testsuite/21_strings/basic_string/requirements/explicit_instantiation/char32_t/1.cc
+++ b/libstdc++-v3/testsuite/21_strings/basic_string/requirements/explicit_instantiation/char32_t/1.cc
@@ -17,6 +17,12 @@
 // along with this library; see the file COPYING3.  If not see
 // <http://www.gnu.org/licenses/>.
 
-#include <string>
+#ifdef _GLIBCXX_DEBUG
+# include <debug/string>
+using namespace __gnu_debug;
+#else
+# include <string>
+using namespace std;
+#endif
 
-template class std::basic_string<char32_t>;
+template class basic_string<char32_t>;
diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/requirements/explicit_instantiation/char8_t/1.cc b/libstdc++-v3/testsuite/21_strings/basic_string/requirements/explicit_instantiation/char8_t/1.cc
index db88b0f47a3..c38f31429da 100644
--- a/libstdc++-v3/testsuite/21_strings/basic_string/requirements/explicit_instantiation/char8_t/1.cc
+++ b/libstdc++-v3/testsuite/21_strings/basic_string/requirements/explicit_instantiation/char8_t/1.cc
@@ -18,6 +18,12 @@
 // along with this library; see the file COPYING3.  If not see
 // <http://www.gnu.org/licenses/>.
 
-#include <string>
+#ifdef _GLIBCXX_DEBUG
+# include <debug/string>
+using namespace __gnu_debug;
+#else
+# include <string>
+using namespace std;
+#endif
 
-template class std::basic_string<char8_t>;
+template class basic_string<char8_t>;
diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/requirements/explicit_instantiation/wchar_t/1.cc b/libstdc++-v3/testsuite/21_strings/basic_string/requirements/explicit_instantiation/wchar_t/1.cc
index 7f16ca4cb5b..a0565baee54 100644
--- a/libstdc++-v3/testsuite/21_strings/basic_string/requirements/explicit_instantiation/wchar_t/1.cc
+++ b/libstdc++-v3/testsuite/21_strings/basic_string/requirements/explicit_instantiation/wchar_t/1.cc
@@ -17,6 +17,12 @@
 // along with this library; see the file COPYING3.  If not see
 // <http://www.gnu.org/licenses/>.
 
-#include <string>
+#ifdef _GLIBCXX_DEBUG
+# include <debug/string>
+using namespace __gnu_debug;
+#else
+# include <string>
+using namespace std;
+#endif
 
-template class std::basic_string<wchar_t>;
+template class basic_string<wchar_t>;
diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/requirements/typedefs.cc b/libstdc++-v3/testsuite/21_strings/basic_string/requirements/typedefs.cc
index 2fc313b9cbf..b90eb020db4 100644
--- a/libstdc++-v3/testsuite/21_strings/basic_string/requirements/typedefs.cc
+++ b/libstdc++-v3/testsuite/21_strings/basic_string/requirements/typedefs.cc
@@ -18,10 +18,19 @@
 // <http://www.gnu.org/licenses/>.
 
 #include <testsuite_containers.h>
-#include <string>
+
+#ifdef _GLIBCXX_DEBUG
+# include <debug/string>
+
+using namespace __gnu_debug;
+#else
+# include <string>
+
+using namespace std;
+#endif
 
 // Check container for required typedefs.
-__gnu_test::types<std::string> t1;
+__gnu_test::types<string> t1;
 #ifdef _GLIBCXX_USE_WCHAR_T
-__gnu_test::types<std::wstring> t2;
+__gnu_test::types<wstring> t2;
 #endif
diff --git a/libstdc++-v3/testsuite/util/exception/safety.h b/libstdc++-v3/testsuite/util/exception/safety.h
index 6c91e740e0d..9309af15405 100644
--- a/libstdc++-v3/testsuite/util/exception/safety.h
+++ b/libstdc++-v3/testsuite/util/exception/safety.h
@@ -266,6 +266,20 @@ namespace __gnu_test
 	iterator (container_type::* _F_erase_point)(iterator);
 	iterator (container_type::* _F_erase_range)(iterator, iterator);
 
+	erase_base()
+	: _F_erase_point(&container_type::erase),
+	  _F_erase_range(&container_type::erase) { }
+      };
+
+    template<typename _Tp1, typename _Tp2, typename _Tp3>
+      struct erase_base<__gnu_debug::basic_string<_Tp1, _Tp2, _Tp3>>
+      {
+	typedef __gnu_debug::basic_string<_Tp1, _Tp2, _Tp3>     container_type;
+	typedef typename container_type::iterator 	iterator;
+
+	iterator (container_type::* _F_erase_point)(iterator);
+	iterator (container_type::* _F_erase_range)(iterator, iterator);
+
 	erase_base()
 	: _F_erase_point(&container_type::erase),
 	  _F_erase_range(&container_type::erase) { }
@@ -681,6 +695,24 @@ namespace __gnu_test
 	typedef typename container_type::const_iterator	const_iterator;
 	typedef typename container_type::value_type 	value_type;
 
+#if _GLIBCXX_USE_CXX11_ABI == 0 || __cplusplus < 201103L
+	iterator (container_type::* _F_insert_point)(iterator, value_type);
+#else
+	iterator (container_type::* _F_insert_point)(const_iterator,
+						     value_type);
+#endif
+
+	insert_base() : _F_insert_point(&container_type::insert) { }
+      };
+
+    template<typename _Tp1, typename _Tp2, typename _Tp3>
+      struct insert_base<__gnu_debug::basic_string<_Tp1, _Tp2, _Tp3>>
+      {
+	typedef __gnu_debug::basic_string<_Tp1, _Tp2, _Tp3> 	container_type;
+	typedef typename container_type::iterator 	iterator;
+	typedef typename container_type::const_iterator	const_iterator;
+	typedef typename container_type::value_type 	value_type;
+
 #if _GLIBCXX_USE_CXX11_ABI == 0 || __cplusplus < 201103L
 	iterator (container_type::* _F_insert_point)(iterator, value_type);
 #else
diff --git a/libstdc++-v3/testsuite/util/testsuite_container_traits.h b/libstdc++-v3/testsuite/util/testsuite_container_traits.h
index fb1f558011c..0bc7a2aa53a 100644
--- a/libstdc++-v3/testsuite/util/testsuite_container_traits.h
+++ b/libstdc++-v3/testsuite/util/testsuite_container_traits.h
@@ -22,6 +22,7 @@
 
 #include <bits/stdc++.h>
 #include <ext/vstring.h>
+#include <debug/string>
 
 namespace __gnu_test
 {
@@ -128,6 +129,17 @@ namespace __gnu_test
       typedef std::true_type	has_insert;
     };
 
+  template<typename _Tp1, typename _Tp2, typename _Tp3>
+    struct traits<__gnu_debug::basic_string<_Tp1, _Tp2, _Tp3>> : public traits_base
+    {
+      typedef std::true_type    is_container;
+      typedef std::true_type    is_reversible;
+      typedef std::true_type    is_allocator_aware;
+
+      typedef std::true_type	has_erase;
+      typedef std::true_type	has_insert;
+    };
+
   template<typename _Tp1, typename _Tp2, typename _Tp3,
 	   template <typename, typename, typename> class _Tp4>
     struct traits<__gnu_cxx::__versa_string<_Tp1, _Tp2, _Tp3, _Tp4>>

Reply via email to