libstdc++: Complete __gnu_debug::string Standard conformity
authorFrançois Dumont <fdumont@gcc.gnu.org>
Sat, 9 Jul 2022 12:15:05 +0000 (14:15 +0200)
committerFrançois Dumont <fdumont@gcc.gnu.org>
Tue, 19 Jul 2022 18:07:28 +0000 (20:07 +0200)
Add testsuite/testsuite_string.h header to help testing __gnu_debug::basic_string like
std::basic_string depending on _GLIBCXX_DEBUG.

Add using of base type methods in __gnu_debug::basic_string to make use of the method
overloads when there is no debug version.

Fix _GLIBCXX_DEBUG_PEDANTIC assertions in <debug/string>. This header has to be used directly
like __gnu_debug::string, it is not included by _GLIBCXX_DEBUG. It means that
_GLIBCXX_DEBUG_PEDANTIC is not considered to define __glibcxx_check_string and
__glibcxx_check_string_len which are then empty macros. Now those macros are defined
directly in <debug/string> and properly consider _GLIBCXX_DEBUG_PEDANTIC.

libstdc++-v3/ChangeLog:

* include/debug/debug.h [_GLIBCXX_DEBUG](__glibcxx_requires_string): Define
using _GLIBCXX_DEBUG_PEDASSERT.
[_GLIBCXX_DEBUG](__glibcxx_requires_string_len): Likewise.
* include/debug/macros.h
(__glibcxx_check_string, __glibcxx_check_string_len): Move...
* include/debug/string
(__glibcxx_check_string, __glibcxx_check_string_len): ...here. And define depending
on _GLIBCXX_DEBUG_PEDANTIC no matter if _GLIBCXX_DEBUG is defined.
Add using of std::string find, rfind, find_first_of, find_last_of, find_first_not_of
and find_last_not_of. Remove debug implementations having no debug assertion.
* testsuite/util/testsuite_string.h: New file. Provides __gnu_test::string and
__gnu_test::wtring which definition depends on _GLIBCXX_DEBUG.
* testsuite/21_strings/basic_string/debug/find1_neg.cc: New test case.
* testsuite/21_strings/basic_string/debug/find2_neg.cc: New test case.
* testsuite/21_strings/basic_string/operations/find/char/1.cc:
Include <testsuite_string.h> and use __gnu_test::string.
* testsuite/21_strings/basic_string/operations/find/char/2.cc: Likewise.
* testsuite/21_strings/basic_string/operations/find/char/3.cc: Likewise.
* testsuite/21_strings/basic_string/operations/find/char/4.cc: Likewise.
* testsuite/21_strings/basic_string/operations/find/char/5.cc: Likewise.
* testsuite/21_strings/basic_string/operations/find/char/6.cc: Likewise.
* testsuite/21_strings/basic_string/operations/find/wchar_t/1.cc:
Include <testsuite_string.h> and use __gnu_test::wstring.
* testsuite/21_strings/basic_string/operations/find/wchar_t/2.cc: Likewise.
* testsuite/21_strings/basic_string/operations/find/wchar_t/3.cc: Likewise.
* testsuite/21_strings/basic_string/operations/find/wchar_t/4.cc: Likewise.
* testsuite/21_strings/basic_string/operations/find/wchar_t/5.cc: Likewise.
* testsuite/21_strings/basic_string/operations/find/wchar_t/6.cc: Likewise.

18 files changed:
libstdc++-v3/include/debug/debug.h
libstdc++-v3/include/debug/macros.h
libstdc++-v3/include/debug/string
libstdc++-v3/testsuite/21_strings/basic_string/debug/find1_neg.cc [new file with mode: 0644]
libstdc++-v3/testsuite/21_strings/basic_string/debug/find2_neg.cc [new file with mode: 0644]
libstdc++-v3/testsuite/21_strings/basic_string/operations/find/char/1.cc
libstdc++-v3/testsuite/21_strings/basic_string/operations/find/char/2.cc
libstdc++-v3/testsuite/21_strings/basic_string/operations/find/char/3.cc
libstdc++-v3/testsuite/21_strings/basic_string/operations/find/char/4.cc
libstdc++-v3/testsuite/21_strings/basic_string/operations/find/char/5.cc
libstdc++-v3/testsuite/21_strings/basic_string/operations/find/char/6.cc
libstdc++-v3/testsuite/21_strings/basic_string/operations/find/wchar_t/1.cc
libstdc++-v3/testsuite/21_strings/basic_string/operations/find/wchar_t/2.cc
libstdc++-v3/testsuite/21_strings/basic_string/operations/find/wchar_t/3.cc
libstdc++-v3/testsuite/21_strings/basic_string/operations/find/wchar_t/4.cc
libstdc++-v3/testsuite/21_strings/basic_string/operations/find/wchar_t/5.cc
libstdc++-v3/testsuite/21_strings/basic_string/operations/find/wchar_t/6.cc
libstdc++-v3/testsuite/util/testsuite_string.h [new file with mode: 0644]

index d3cdfbc..28e250f 100644 (file)
@@ -118,9 +118,10 @@ namespace __gnu_debug
   __glibcxx_check_heap(_First,_Last)
 # define __glibcxx_requires_heap_pred(_First,_Last,_Pred)      \
   __glibcxx_check_heap_pred(_First,_Last,_Pred)
-# define __glibcxx_requires_string(_String) __glibcxx_check_string(_String)
+# define __glibcxx_requires_string(_String)    \
+  _GLIBCXX_DEBUG_PEDASSERT(_String != 0)
 # define __glibcxx_requires_string_len(_String,_Len)   \
-  __glibcxx_check_string_len(_String,_Len)
+  _GLIBCXX_DEBUG_PEDASSERT(_String != 0 || _Len == 0)
 # define __glibcxx_requires_irreflexive(_First,_Last)  \
   __glibcxx_check_irreflexive(_First,_Last)
 # define __glibcxx_requires_irreflexive2(_First,_Last) \
index 7b86292..5fb6832 100644 (file)
@@ -467,8 +467,4 @@ _GLIBCXX_DEBUG_VERIFY(_This.get_allocator() == _Other.get_allocator(),      \
                      _M_message(__gnu_debug::__msg_equal_allocs)       \
                      ._M_sequence(_This, "this"))
 
-#define __glibcxx_check_string(_String) _GLIBCXX_DEBUG_PEDASSERT(_String != 0)
-#define __glibcxx_check_string_len(_String,_Len) \
-  _GLIBCXX_DEBUG_PEDASSERT(_String != 0 || _Len == 0)
-
 #endif
index 3ec55d4..a4482db 100644 (file)
 # define _GLIBCXX_INSERT_RETURNS_ITERATOR_ONLY(expr)
 #endif
 
+#ifdef _GLIBCXX_DEBUG_PEDANTIC
+# define __glibcxx_check_string(_String)                               \
+  _GLIBCXX_DEBUG_VERIFY_STR_COND_AT(_String != 0,              \
+                                   __FILE__, __LINE__,         \
+                                   __PRETTY_FUNCTION__);
+# define __glibcxx_check_string_len(_String,_Len)              \
+  _GLIBCXX_DEBUG_VERIFY_STR_COND_AT(_String != 0 || _Len == 0, \
+                                   __FILE__, __LINE__,         \
+                                   __PRETTY_FUNCTION__);
+#else
+# define __glibcxx_check_string(_String)
+# define __glibcxx_check_string_len(_String,_Len)
+#endif
+
 namespace __gnu_debug
 {
   /** Checks that __s is non-NULL or __n == 0, and then returns __s. */
@@ -868,34 +882,28 @@ namespace __gnu_debug
 
       using _Base::get_allocator;
 
-      size_type
-      find(const basic_string& __str, size_type __pos = 0) const
-       _GLIBCXX_NOEXCEPT
-      { return _Base::find(__str, __pos); }
+      using _Base::find;
 
+      _GLIBCXX20_CONSTEXPR
       size_type
       find(const _CharT* __s, size_type __pos, size_type __n) const
+       _GLIBCXX_NOEXCEPT
       {
        __glibcxx_check_string(__s);
        return _Base::find(__s, __pos, __n);
       }
 
+      _GLIBCXX20_CONSTEXPR
       size_type
-      find(const _CharT* __s, size_type __pos = 0) const
+      find(const _CharT* __s, size_type __pos = 0) const _GLIBCXX_NOEXCEPT
       {
        __glibcxx_check_string(__s);
        return _Base::find(__s, __pos);
       }
 
-      size_type
-      find(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT
-      { return _Base::find(__c, __pos); }
-
-      size_type
-      rfind(const basic_string& __str, size_type __pos = _Base::npos) const
-       _GLIBCXX_NOEXCEPT
-      { return _Base::rfind(__str, __pos); }
+      using _Base::rfind;
 
+      _GLIBCXX20_CONSTEXPR
       size_type
       rfind(const _CharT* __s, size_type __pos, size_type __n) const
       {
@@ -903,6 +911,7 @@ namespace __gnu_debug
        return _Base::rfind(__s, __pos, __n);
       }
 
+      _GLIBCXX20_CONSTEXPR
       size_type
       rfind(const _CharT* __s, size_type __pos = _Base::npos) const
       {
@@ -910,105 +919,85 @@ namespace __gnu_debug
        return _Base::rfind(__s, __pos);
       }
 
-      size_type
-      rfind(_CharT __c, size_type __pos = _Base::npos) const _GLIBCXX_NOEXCEPT
-      { return _Base::rfind(__c, __pos); }
-
-      size_type
-      find_first_of(const basic_string& __str, size_type __pos = 0) const
-       _GLIBCXX_NOEXCEPT
-      { return _Base::find_first_of(__str, __pos); }
+      using _Base::find_first_of;
 
+      _GLIBCXX20_CONSTEXPR
       size_type
       find_first_of(const _CharT* __s, size_type __pos, size_type __n) const
+       _GLIBCXX_NOEXCEPT
       {
        __glibcxx_check_string(__s);
        return _Base::find_first_of(__s, __pos, __n);
       }
 
+      _GLIBCXX20_CONSTEXPR
       size_type
-      find_first_of(const _CharT* __s, size_type __pos = 0) const
+      find_first_of(const _CharT* __s, size_type __pos = 0) const _GLIBCXX_NOEXCEPT
       {
        __glibcxx_check_string(__s);
        return _Base::find_first_of(__s, __pos);
       }
 
-      size_type
-      find_first_of(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT
-      { return _Base::find_first_of(__c, __pos); }
-
-      size_type
-      find_last_of(const basic_string& __str,
-                  size_type __pos = _Base::npos) const _GLIBCXX_NOEXCEPT
-      { return _Base::find_last_of(__str, __pos); }
+      using _Base::find_last_of;
 
+      _GLIBCXX20_CONSTEXPR
       size_type
       find_last_of(const _CharT* __s, size_type __pos, size_type __n) const
+       _GLIBCXX_NOEXCEPT
       {
        __glibcxx_check_string(__s);
        return _Base::find_last_of(__s, __pos, __n);
       }
 
+      _GLIBCXX20_CONSTEXPR
       size_type
       find_last_of(const _CharT* __s, size_type __pos = _Base::npos) const
+       _GLIBCXX_NOEXCEPT
       {
        __glibcxx_check_string(__s);
        return _Base::find_last_of(__s, __pos);
       }
 
-      size_type
-      find_last_of(_CharT __c, size_type __pos = _Base::npos) const
-       _GLIBCXX_NOEXCEPT
-      { return _Base::find_last_of(__c, __pos); }
-
-      size_type
-      find_first_not_of(const basic_string& __str, size_type __pos = 0) const
-       _GLIBCXX_NOEXCEPT
-      { return _Base::find_first_not_of(__str, __pos); }
+      using _Base::find_first_not_of;
 
+      _GLIBCXX20_CONSTEXPR
       size_type
       find_first_not_of(const _CharT* __s, size_type __pos, size_type __n) const
+       _GLIBCXX_NOEXCEPT
       {
        __glibcxx_check_string_len(__s, __n);
        return _Base::find_first_not_of(__s, __pos, __n);
       }
 
+      _GLIBCXX20_CONSTEXPR
       size_type
       find_first_not_of(const _CharT* __s, size_type __pos = 0) const
+       _GLIBCXX_NOEXCEPT
       {
        __glibcxx_check_string(__s);
        return _Base::find_first_not_of(__s, __pos);
       }
 
-      size_type
-      find_first_not_of(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT
-      { return _Base::find_first_not_of(__c, __pos); }
-
-      size_type
-      find_last_not_of(const basic_string& __str,
-                      size_type __pos = _Base::npos) const
-       _GLIBCXX_NOEXCEPT
-      { return _Base::find_last_not_of(__str, __pos); }
+      using _Base::find_last_not_of;
 
+      _GLIBCXX20_CONSTEXPR
       size_type
       find_last_not_of(const _CharT* __s, size_type __pos, size_type __n) const
+       _GLIBCXX_NOEXCEPT
       {
        __glibcxx_check_string(__s);
        return _Base::find_last_not_of(__s, __pos, __n);
       }
 
+      _GLIBCXX20_CONSTEXPR
       size_type
       find_last_not_of(const _CharT* __s, size_type __pos = _Base::npos) const
+       _GLIBCXX_NOEXCEPT
       {
        __glibcxx_check_string(__s);
        return _Base::find_last_not_of(__s, __pos);
       }
 
-      size_type
-      find_last_not_of(_CharT __c, size_type __pos = _Base::npos) const
-       _GLIBCXX_NOEXCEPT
-      { return _Base::find_last_not_of(__c, __pos); }
-
       basic_string
       substr(size_type __pos = 0, size_type __n = _Base::npos) const
       { return basic_string(_Base::substr(__pos, __n)); }
diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/debug/find1_neg.cc b/libstdc++-v3/testsuite/21_strings/basic_string/debug/find1_neg.cc
new file mode 100644 (file)
index 0000000..02babbc
--- /dev/null
@@ -0,0 +1,35 @@
+// Copyright (C) 2022 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-do run { xfail *-*-* } }
+
+#define _GLIBCXX_DEBUG_PEDANTIC
+
+#include <debug/string>
+
+void test01()
+{
+  const char* __null_str = 0;
+  __gnu_debug::string str;
+  str.find(__null_str);
+}
+
+int main()
+{
+  test01();
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/debug/find2_neg.cc b/libstdc++-v3/testsuite/21_strings/basic_string/debug/find2_neg.cc
new file mode 100644 (file)
index 0000000..89250e2
--- /dev/null
@@ -0,0 +1,35 @@
+// Copyright (C) 2022 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-do run { xfail *-*-* } }
+
+#define _GLIBCXX_DEBUG_PEDANTIC
+
+#include <debug/string>
+
+void test01()
+{
+  const char* __null_str = 0;
+  __gnu_debug::string str;
+  str.find(__null_str, 0, 0);
+}
+
+int main()
+{
+  test01();
+  return 0;
+}
index e76473d..862cfef 100644 (file)
 
 // 21.3.6.1 basic_string find
 
-#include <string>
+#include <testsuite_string.h>
 #include <testsuite_hooks.h>
 
 void test01(void)
 {
-  typedef std::string::size_type csize_type;
-  typedef std::string::const_reference cref;
-  typedef std::string::reference ref;
-  csize_type npos = std::string::npos;
+  typedef __gnu_test::string::size_type csize_type;
+  typedef __gnu_test::string::const_reference cref;
+  typedef __gnu_test::string::reference ref;
+  csize_type npos = __gnu_test::string::npos;
   csize_type csz01, csz02;
 
   const char str_lit01[] = "mave";
-  const std::string str01("mavericks, santa cruz");
-  std::string str02(str_lit01);
-  std::string str03("s, s");
-  std::string str04;
+  const __gnu_test::string str01("mavericks, santa cruz");
+  __gnu_test::string str02(str_lit01);
+  __gnu_test::string str03("s, s");
+  __gnu_test::string str04;
 
   // size_type find(const string&, size_type pos = 0) const;
   csz01 = str01.find(str01);
index baeab8b..756ad85 100644 (file)
 
 // 21.3.6.3 basic_string find_first_of
 
-#include <string>
+#include <testsuite_string.h>
 #include <testsuite_hooks.h>
 
 void test02(void)
 {
-  typedef std::string::size_type csize_type;
-  csize_type npos = std::string::npos;
+  typedef __gnu_test::string::size_type csize_type;
+  csize_type npos = __gnu_test::string::npos;
   csize_type csz01, csz02;
 
   const char str_lit01[] = "mave";
-  const std::string str01("mavericks, santa cruz");
-  std::string str02(str_lit01);
-  std::string str03("s, s");
-  std::string str04;
+  const __gnu_test::string str01("mavericks, santa cruz");
+  __gnu_test::string str02(str_lit01);
+  __gnu_test::string str03("s, s");
+  __gnu_test::string str04;
 
   // size_type find_first_of(const string&, size_type pos = 0) const;
-  std::string str05("xena rulez");
+  __gnu_test::string str05("xena rulez");
   csz01 = str01.find_first_of(str01);
   VERIFY( csz01 == 0 );
   csz01 = str01.find_first_of(str01, 4);
index 7c21080..8386ae8 100644 (file)
 
 // 21.3.6.5 basic_string find_first_not_of
 
-#include <string>
+#include <testsuite_string.h>
 #include <testsuite_hooks.h>
 
 void test03(void)
 {
-  typedef std::string::size_type csize_type;
-  csize_type npos = std::string::npos;
+  typedef __gnu_test::string::size_type csize_type;
+  csize_type npos = __gnu_test::string::npos;
   csize_type csz01;
 
-  const std::string str01("Bob Rock, per me");
+  const __gnu_test::string str01("Bob Rock, per me");
   const char str_lit01[] = "Bob Rock";
-  std::string str02("ovvero Trivi");
-  std::string str03(str_lit01);
-  std::string str04;
+  __gnu_test::string str02("ovvero Trivi");
+  __gnu_test::string str03(str_lit01);
+  __gnu_test::string str04;
 
   // size_type find_first_not_of(const string&, size_type pos = 0) const;
   csz01 = str01.find_first_not_of(str01);
index cf8c0c9..72965d0 100644 (file)
 
 // 21.3.6.1 basic_string find
 
-#include <string>
+#include <testsuite_string.h>
 #include <testsuite_hooks.h>
 
 // libstdc++/31401
 void test01()
 {
-  typedef std::string::size_type csize_type;
-  csize_type npos = std::string::npos;
+  typedef __gnu_test::string::size_type csize_type;
+  csize_type npos = __gnu_test::string::npos;
 
-  std::string use = "anu";
+  __gnu_test::string use = "anu";
   csize_type pos1 = use.find("a", npos);
 
   VERIFY( pos1 == npos );
index 7464a3c..a366975 100644 (file)
 // [string::find.first.not.of]
 // [string::find.last.not.of]
 
-#include <string>
+#include <testsuite_string.h>
 #include <testsuite_hooks.h>
 
 void
 test03()
 {
   std::string_view str1("bar");
-  std::string str2("foobar");
+  __gnu_test::string str2("foobar");
 
   auto x = str2.find(str1);
   VERIFY (x == 3);
index b901e7d..51d7b25 100644 (file)
 
 // C++11 21.4.7.2 [string::find] basic_string find
 
-#include <string>
+#include <testsuite_string.h>
 #include <testsuite_hooks.h>
 
 // https://gcc.gnu.org/ml/libstdc++/2017-01/msg00021.html
 void test01()
 {
-  typedef std::string string_type;
+  typedef __gnu_test::string string_type;
   string_type::size_type npos = string_type::npos;
 
   string_type use = "aaa";
index f1f5548..bb65c0c 100644 (file)
 
 // 21.3.6.1 basic_string find
 
-#include <string>
+#include <testsuite_string.h>
 #include <testsuite_hooks.h>
 
 void test01(void)
 {
-  typedef std::wstring::size_type csize_type;
-  typedef std::wstring::const_reference cref;
-  typedef std::wstring::reference ref;
-  csize_type npos = std::wstring::npos;
+  typedef __gnu_test::wstring::size_type csize_type;
+  typedef __gnu_test::wstring::const_reference cref;
+  typedef __gnu_test::wstring::reference ref;
+  csize_type npos = __gnu_test::wstring::npos;
   csize_type csz01, csz02;
 
   const wchar_t str_lit01[] = L"mave";
-  const std::wstring str01(L"mavericks, santa cruz");
-  std::wstring str02(str_lit01);
-  std::wstring str03(L"s, s");
-  std::wstring str04;
+  const __gnu_test::wstring str01(L"mavericks, santa cruz");
+  __gnu_test::wstring str02(str_lit01);
+  __gnu_test::wstring str03(L"s, s");
+  __gnu_test::wstring str04;
 
   // size_type find(const wstring&, size_type pos = 0) const;
   csz01 = str01.find(str01);
index e7ab9e8..0bd1533 100644 (file)
 
 // 21.3.6.3 basic_string find_first_of
 
-#include <string>
+#include <testsuite_string.h>
 #include <testsuite_hooks.h>
 
 void test02(void)
 {
-  typedef std::wstring::size_type csize_type;
-  csize_type npos = std::wstring::npos;
+  typedef __gnu_test::wstring::size_type csize_type;
+  csize_type npos = __gnu_test::wstring::npos;
   csize_type csz01, csz02;
 
   const wchar_t str_lit01[] = L"mave";
-  const std::wstring str01(L"mavericks, santa cruz");
-  std::wstring str02(str_lit01);
-  std::wstring str03(L"s, s");
-  std::wstring str04;
+  const __gnu_test::wstring str01(L"mavericks, santa cruz");
+  __gnu_test::wstring str02(str_lit01);
+  __gnu_test::wstring str03(L"s, s");
+  __gnu_test::wstring str04;
 
   // size_type find_first_of(const wstring&, size_type pos = 0) const;
-  std::wstring str05(L"xena rulez");
+  __gnu_test::wstring str05(L"xena rulez");
   csz01 = str01.find_first_of(str01);
   VERIFY( csz01 == 0 );
   csz01 = str01.find_first_of(str01, 4);
index 9daf26b..8c595fd 100644 (file)
 
 // 21.3.6.5 basic_string find_first_not_of
 
-#include <string>
+#include <testsuite_string.h>
 #include <testsuite_hooks.h>
 
 void test03(void)
 {
-  typedef std::wstring::size_type csize_type;
-  csize_type npos = std::wstring::npos;
+  typedef __gnu_test::wstring::size_type csize_type;
+  csize_type npos = __gnu_test::wstring::npos;
   csize_type csz01;
 
-  const std::wstring str01(L"Bob Rock, per me");
+  const __gnu_test::wstring str01(L"Bob Rock, per me");
   const wchar_t str_lit01[] = L"Bob Rock";
-  std::wstring str02(L"ovvero Trivi");
-  std::wstring str03(str_lit01);
-  std::wstring str04;
+  __gnu_test::wstring str02(L"ovvero Trivi");
+  __gnu_test::wstring str03(str_lit01);
+  __gnu_test::wstring str04;
 
   // size_type find_first_not_of(const string&, size_type pos = 0) const;
   csz01 = str01.find_first_not_of(str01);
index f9b9605..98c3a18 100644 (file)
 
 // 21.3.6.1 basic_string find
 
-#include <string>
+#include <testsuite_string.h>
 #include <testsuite_hooks.h>
 
 // libstdc++/31401
 void test01()
 {
-  typedef std::wstring::size_type csize_type;
-  csize_type npos = std::wstring::npos;
+  typedef __gnu_test::wstring::size_type csize_type;
+  csize_type npos = __gnu_test::wstring::npos;
 
-  std::wstring use = L"anu";
+  __gnu_test::wstring use = L"anu";
   csize_type pos1 = use.find(L"a", npos);
 
   VERIFY( pos1 == npos );
index d04e613..76126a7 100644 (file)
 // [string::find.first.not.of]
 // [string::find.last.not.of]
 
-#include <string>
+#include <testsuite_string.h>
 #include <testsuite_hooks.h>
 
 void
 test03()
 {
   std::wstring_view str1(L"bar");
-  std::wstring str2(L"foobar");
+  __gnu_test::wstring str2(L"foobar");
 
   auto x = str2.find(str1);
   VERIFY (x == 3);
index 24a8c81..58c4db0 100644 (file)
 
 // C++11 21.4.7.2 [string::find] basic_string find
 
-#include <string>
+#include <testsuite_string.h>
 #include <testsuite_hooks.h>
 
 // https://gcc.gnu.org/ml/libstdc++/2017-01/msg00021.html
 void test01()
 {
-  typedef std::wstring string_type;
+  typedef __gnu_test::wstring string_type;
   string_type::size_type npos = string_type::npos;
 
   string_type use = L"aaa";
diff --git a/libstdc++-v3/testsuite/util/testsuite_string.h b/libstdc++-v3/testsuite/util/testsuite_string.h
new file mode 100644 (file)
index 0000000..7121ff8
--- /dev/null
@@ -0,0 +1,20 @@
+#ifndef _GLIBCXX_TESTSUITE_STRING_H
+#define _GLIBCXX_TESTSUITE_STRING_H
+
+#ifdef _GLIBCXX_DEBUG
+# include <debug/string>
+namespace __gnu_test
+{
+  using __gnu_debug::string;
+  using __gnu_debug::wstring;
+}
+#else
+# include <string>
+namespace __gnu_test
+{
+  using std::string;
+  using std::wstring;
+}
+#endif
+
+#endif