diff options
author | François Dumont <fdumont@gcc.gnu.org> | 2022-07-09 14:15:05 +0200 |
---|---|---|
committer | François Dumont <fdumont@gcc.gnu.org> | 2022-07-19 20:07:28 +0200 |
commit | c66dc02384782e9456ceffb2f72b8f724c4f6a94 (patch) | |
tree | 23a45689c44df6d10cfc46552031a1f5a70d65d9 /libstdc++-v3/testsuite | |
parent | 68f37670eff0b872ce5dfd382c8d8f3206bdfc27 (diff) |
libstdc++: Complete __gnu_debug::string Standard conformity
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.
Diffstat (limited to 'libstdc++-v3/testsuite')
15 files changed, 154 insertions, 64 deletions
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 index 00000000000..02babbc59e0 --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/debug/find1_neg.cc @@ -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 index 00000000000..89250e2d874 --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/debug/find2_neg.cc @@ -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; +} diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/operations/find/char/1.cc b/libstdc++-v3/testsuite/21_strings/basic_string/operations/find/char/1.cc index e76473d88c0..862cfefee69 100644 --- a/libstdc++-v3/testsuite/21_strings/basic_string/operations/find/char/1.cc +++ b/libstdc++-v3/testsuite/21_strings/basic_string/operations/find/char/1.cc @@ -19,22 +19,22 @@ // 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); diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/operations/find/char/2.cc b/libstdc++-v3/testsuite/21_strings/basic_string/operations/find/char/2.cc index baeab8b933f..756ad85dcaa 100644 --- a/libstdc++-v3/testsuite/21_strings/basic_string/operations/find/char/2.cc +++ b/libstdc++-v3/testsuite/21_strings/basic_string/operations/find/char/2.cc @@ -19,23 +19,23 @@ // 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); diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/operations/find/char/3.cc b/libstdc++-v3/testsuite/21_strings/basic_string/operations/find/char/3.cc index 7c21080c5ff..8386ae8264d 100644 --- a/libstdc++-v3/testsuite/21_strings/basic_string/operations/find/char/3.cc +++ b/libstdc++-v3/testsuite/21_strings/basic_string/operations/find/char/3.cc @@ -19,20 +19,20 @@ // 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); diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/operations/find/char/4.cc b/libstdc++-v3/testsuite/21_strings/basic_string/operations/find/char/4.cc index cf8c0c9f36d..72965d0731f 100644 --- a/libstdc++-v3/testsuite/21_strings/basic_string/operations/find/char/4.cc +++ b/libstdc++-v3/testsuite/21_strings/basic_string/operations/find/char/4.cc @@ -19,16 +19,16 @@ // 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 ); diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/operations/find/char/5.cc b/libstdc++-v3/testsuite/21_strings/basic_string/operations/find/char/5.cc index 7464a3cb97f..a366975308c 100644 --- a/libstdc++-v3/testsuite/21_strings/basic_string/operations/find/char/5.cc +++ b/libstdc++-v3/testsuite/21_strings/basic_string/operations/find/char/5.cc @@ -24,14 +24,14 @@ // [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); diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/operations/find/char/6.cc b/libstdc++-v3/testsuite/21_strings/basic_string/operations/find/char/6.cc index b901e7d049f..51d7b25c1c6 100644 --- a/libstdc++-v3/testsuite/21_strings/basic_string/operations/find/char/6.cc +++ b/libstdc++-v3/testsuite/21_strings/basic_string/operations/find/char/6.cc @@ -19,13 +19,13 @@ // 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"; diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/operations/find/wchar_t/1.cc b/libstdc++-v3/testsuite/21_strings/basic_string/operations/find/wchar_t/1.cc index f1f554895ee..bb65c0cd15f 100644 --- a/libstdc++-v3/testsuite/21_strings/basic_string/operations/find/wchar_t/1.cc +++ b/libstdc++-v3/testsuite/21_strings/basic_string/operations/find/wchar_t/1.cc @@ -19,22 +19,22 @@ // 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); diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/operations/find/wchar_t/2.cc b/libstdc++-v3/testsuite/21_strings/basic_string/operations/find/wchar_t/2.cc index e7ab9e8ca20..0bd1533d32e 100644 --- a/libstdc++-v3/testsuite/21_strings/basic_string/operations/find/wchar_t/2.cc +++ b/libstdc++-v3/testsuite/21_strings/basic_string/operations/find/wchar_t/2.cc @@ -19,23 +19,23 @@ // 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); diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/operations/find/wchar_t/3.cc b/libstdc++-v3/testsuite/21_strings/basic_string/operations/find/wchar_t/3.cc index 9daf26bf4f4..8c595fda3f9 100644 --- a/libstdc++-v3/testsuite/21_strings/basic_string/operations/find/wchar_t/3.cc +++ b/libstdc++-v3/testsuite/21_strings/basic_string/operations/find/wchar_t/3.cc @@ -19,20 +19,20 @@ // 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); diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/operations/find/wchar_t/4.cc b/libstdc++-v3/testsuite/21_strings/basic_string/operations/find/wchar_t/4.cc index f9b9605212a..98c3a18accd 100644 --- a/libstdc++-v3/testsuite/21_strings/basic_string/operations/find/wchar_t/4.cc +++ b/libstdc++-v3/testsuite/21_strings/basic_string/operations/find/wchar_t/4.cc @@ -19,16 +19,16 @@ // 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 ); diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/operations/find/wchar_t/5.cc b/libstdc++-v3/testsuite/21_strings/basic_string/operations/find/wchar_t/5.cc index d04e6138956..76126a79988 100644 --- a/libstdc++-v3/testsuite/21_strings/basic_string/operations/find/wchar_t/5.cc +++ b/libstdc++-v3/testsuite/21_strings/basic_string/operations/find/wchar_t/5.cc @@ -24,14 +24,14 @@ // [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); diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/operations/find/wchar_t/6.cc b/libstdc++-v3/testsuite/21_strings/basic_string/operations/find/wchar_t/6.cc index 24a8c8178fe..58c4db05163 100644 --- a/libstdc++-v3/testsuite/21_strings/basic_string/operations/find/wchar_t/6.cc +++ b/libstdc++-v3/testsuite/21_strings/basic_string/operations/find/wchar_t/6.cc @@ -19,13 +19,13 @@ // 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 index 00000000000..7121ff8ec6d --- /dev/null +++ b/libstdc++-v3/testsuite/util/testsuite_string.h @@ -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 |