mirror of git://gcc.gnu.org/git/gcc.git
libstdc++: Add __gnu_debug::basic_string<>::compare overloads
Rather than adding those implementations we are adding a: using _Base::compare; so that any compare method not implemented at __gnu_debug::basic_string level are injected from the base class. Also review how __gnu_debug::basic_string is tested. Now require to define _GLIBCXX_TEST_DEBUG_STRING when running 'make check-debug'. libstdc++-v3/ChangeLog * include/debug/string: Add using _Base::compare. (__gnu_debug::basic_string<>::compare(const basic_string<>&)): Remove. (__gnu_debug::basic_string<>::compare(size_type, size_type, const basic_string<>&)): Remove. (__gnu_debug::basic_string<>::compare(size_type, size_type, const basic_string<>&, size_type, size_type)): Remove. * testsuite/util/testsuite_string.h [_GLIBCXX_TEST_DEBUG_STRING]: Include <debug/string>. * testsuite/21_strings/basic_string/operations/compare/char/1.cc: Include testsuite_string.h and use __gnu_test::string. * testsuite/21_strings/basic_string/operations/compare/char/13650.cc: Likewise. * testsuite/21_strings/basic_string/operations/compare/char/2.cc: Likewise. * testsuite/21_strings/basic_string/operations/rfind/char/1.cc: Likewise. * testsuite/21_strings/basic_string/operations/rfind/char/2.cc: Likewise. * testsuite/21_strings/basic_string/operations/rfind/char/3.cc: Likewise. * testsuite/21_strings/basic_string/operations/compare/wchar_t/1.cc: Include testsuite_string.h and use __gnu_test::wstring. * testsuite/21_strings/basic_string/operations/compare/wchar_t/13650.cc: Likewise. * testsuite/21_strings/basic_string/operations/compare/wchar_t/2.cc: Likewise.
This commit is contained in:
parent
bc0d700b57
commit
f77281b25c
|
|
@ -1023,22 +1023,11 @@ namespace __gnu_debug
|
||||||
substr(size_type __pos = 0, size_type __n = _Base::npos) const
|
substr(size_type __pos = 0, size_type __n = _Base::npos) const
|
||||||
{ return basic_string(_Base::substr(__pos, __n)); }
|
{ return basic_string(_Base::substr(__pos, __n)); }
|
||||||
|
|
||||||
int
|
using _Base::compare;
|
||||||
compare(const basic_string& __str) const
|
|
||||||
{ return _Base::compare(__str); }
|
|
||||||
|
|
||||||
|
_GLIBCXX20_CONSTEXPR
|
||||||
int
|
int
|
||||||
compare(size_type __pos1, size_type __n1,
|
compare(const _CharT* __s) const _GLIBCXX_NOEXCEPT
|
||||||
const basic_string& __str) const
|
|
||||||
{ return _Base::compare(__pos1, __n1, __str); }
|
|
||||||
|
|
||||||
int
|
|
||||||
compare(size_type __pos1, size_type __n1, const basic_string& __str,
|
|
||||||
size_type __pos2, size_type __n2) const
|
|
||||||
{ return _Base::compare(__pos1, __n1, __str, __pos2, __n2); }
|
|
||||||
|
|
||||||
int
|
|
||||||
compare(const _CharT* __s) const
|
|
||||||
{
|
{
|
||||||
__glibcxx_check_string(__s);
|
__glibcxx_check_string(__s);
|
||||||
return _Base::compare(__s);
|
return _Base::compare(__s);
|
||||||
|
|
@ -1046,6 +1035,7 @@ namespace __gnu_debug
|
||||||
|
|
||||||
// _GLIBCXX_RESOLVE_LIB_DEFECTS
|
// _GLIBCXX_RESOLVE_LIB_DEFECTS
|
||||||
// 5. string::compare specification questionable
|
// 5. string::compare specification questionable
|
||||||
|
_GLIBCXX20_CONSTEXPR
|
||||||
int
|
int
|
||||||
compare(size_type __pos1, size_type __n1, const _CharT* __s) const
|
compare(size_type __pos1, size_type __n1, const _CharT* __s) const
|
||||||
{
|
{
|
||||||
|
|
@ -1055,6 +1045,7 @@ namespace __gnu_debug
|
||||||
|
|
||||||
// _GLIBCXX_RESOLVE_LIB_DEFECTS
|
// _GLIBCXX_RESOLVE_LIB_DEFECTS
|
||||||
// 5. string::compare specification questionable
|
// 5. string::compare specification questionable
|
||||||
|
_GLIBCXX20_CONSTEXPR
|
||||||
int
|
int
|
||||||
compare(size_type __pos1, size_type __n1,const _CharT* __s,
|
compare(size_type __pos1, size_type __n1,const _CharT* __s,
|
||||||
size_type __n2) const
|
size_type __n2) const
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@
|
||||||
// NB compare should be thought of as a lexographical compare, ie how
|
// NB compare should be thought of as a lexographical compare, ie how
|
||||||
// things would be sorted in a dictionary.
|
// things would be sorted in a dictionary.
|
||||||
|
|
||||||
#include <string>
|
#include <testsuite_string.h>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <testsuite_hooks.h>
|
#include <testsuite_hooks.h>
|
||||||
|
|
||||||
|
|
@ -67,7 +67,7 @@ test_value(int result, want_value expected)
|
||||||
int
|
int
|
||||||
test01()
|
test01()
|
||||||
{
|
{
|
||||||
using namespace std;
|
using namespace __gnu_test;
|
||||||
|
|
||||||
string str_0("costa rica");
|
string str_0("costa rica");
|
||||||
string str_1("costa marbella");
|
string str_1("costa marbella");
|
||||||
|
|
|
||||||
|
|
@ -19,13 +19,13 @@
|
||||||
|
|
||||||
// 21.3.6.8 basic_string::compare [lib.string::compare]
|
// 21.3.6.8 basic_string::compare [lib.string::compare]
|
||||||
|
|
||||||
#include <string>
|
#include <testsuite_string.h>
|
||||||
#include <testsuite_hooks.h>
|
#include <testsuite_hooks.h>
|
||||||
|
|
||||||
// libstdc++/13650
|
// libstdc++/13650
|
||||||
void test01()
|
void test01()
|
||||||
{
|
{
|
||||||
using namespace std;
|
using namespace __gnu_test;
|
||||||
|
|
||||||
const char lit_01[] = { 'w', 'e', '\0', 'r', 'd' };
|
const char lit_01[] = { 'w', 'e', '\0', 'r', 'd' };
|
||||||
const char lit_02[] = { 'w', 'e', 'i', '\0', 'd' };
|
const char lit_02[] = { 'w', 'e', 'i', '\0', 'd' };
|
||||||
|
|
|
||||||
|
|
@ -19,14 +19,14 @@
|
||||||
|
|
||||||
// [string::compare]
|
// [string::compare]
|
||||||
|
|
||||||
#include <string>
|
#include <testsuite_string.h>
|
||||||
#include <testsuite_hooks.h>
|
#include <testsuite_hooks.h>
|
||||||
|
|
||||||
void
|
void
|
||||||
test03()
|
test03()
|
||||||
{
|
{
|
||||||
std::string_view str1("foobar");
|
std::string_view str1("foobar");
|
||||||
std::string str2("foobar");
|
__gnu_test::string str2("foobar");
|
||||||
|
|
||||||
auto x = str2.compare(str1);
|
auto x = str2.compare(str1);
|
||||||
VERIFY (x == 0);
|
VERIFY (x == 0);
|
||||||
|
|
@ -52,7 +52,7 @@ test03()
|
||||||
void
|
void
|
||||||
test04()
|
test04()
|
||||||
{
|
{
|
||||||
const std::string str("a");
|
const __gnu_test::string str("a");
|
||||||
char c = 'a';
|
char c = 'a';
|
||||||
int res = str.compare(0, 1, &c, 1);
|
int res = str.compare(0, 1, &c, 1);
|
||||||
VERIFY ( !res );
|
VERIFY ( !res );
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@
|
||||||
// NB compare should be thought of as a lexographical compare, ie how
|
// NB compare should be thought of as a lexographical compare, ie how
|
||||||
// things would be sorted in a dictionary.
|
// things would be sorted in a dictionary.
|
||||||
|
|
||||||
#include <string>
|
#include <testsuite_string.h>
|
||||||
#include <testsuite_hooks.h>
|
#include <testsuite_hooks.h>
|
||||||
|
|
||||||
enum want_value {lt=0, z=1, gt=2};
|
enum want_value {lt=0, z=1, gt=2};
|
||||||
|
|
@ -67,7 +67,7 @@ test_value(int result, want_value expected)
|
||||||
int
|
int
|
||||||
test01()
|
test01()
|
||||||
{
|
{
|
||||||
using namespace std;
|
using namespace __gnu_test;
|
||||||
|
|
||||||
wstring str_0(L"costa rica");
|
wstring str_0(L"costa rica");
|
||||||
wstring str_1(L"costa marbella");
|
wstring str_1(L"costa marbella");
|
||||||
|
|
|
||||||
|
|
@ -19,13 +19,13 @@
|
||||||
|
|
||||||
// 21.3.6.8 basic_string::compare [lib.string::compare]
|
// 21.3.6.8 basic_string::compare [lib.string::compare]
|
||||||
|
|
||||||
#include <string>
|
#include <testsuite_string.h>
|
||||||
#include <testsuite_hooks.h>
|
#include <testsuite_hooks.h>
|
||||||
|
|
||||||
// libstdc++/13650
|
// libstdc++/13650
|
||||||
void test01()
|
void test01()
|
||||||
{
|
{
|
||||||
using namespace std;
|
using namespace __gnu_test;
|
||||||
|
|
||||||
const wchar_t lit_01[] = { L'w', L'e', L'\0', L'r', L'd' };
|
const wchar_t lit_01[] = { L'w', L'e', L'\0', L'r', L'd' };
|
||||||
const wchar_t lit_02[] = { L'w', L'e', L'i', L'\0', L'd' };
|
const wchar_t lit_02[] = { L'w', L'e', L'i', L'\0', L'd' };
|
||||||
|
|
|
||||||
|
|
@ -19,14 +19,14 @@
|
||||||
|
|
||||||
// [string::compare]
|
// [string::compare]
|
||||||
|
|
||||||
#include <string>
|
#include <testsuite_string.h>
|
||||||
#include <testsuite_hooks.h>
|
#include <testsuite_hooks.h>
|
||||||
|
|
||||||
void
|
void
|
||||||
test03()
|
test03()
|
||||||
{
|
{
|
||||||
std::wstring_view str1(L"foobar");
|
std::wstring_view str1(L"foobar");
|
||||||
std::wstring str2(L"foobar");
|
__gnu_test::wstring str2(L"foobar");
|
||||||
|
|
||||||
auto x = str2.compare(str1);
|
auto x = str2.compare(str1);
|
||||||
VERIFY (x == 0);
|
VERIFY (x == 0);
|
||||||
|
|
@ -52,7 +52,7 @@ test03()
|
||||||
void
|
void
|
||||||
test04()
|
test04()
|
||||||
{
|
{
|
||||||
const std::wstring str(L"a");
|
const __gnu_test::wstring str(L"a");
|
||||||
|
|
||||||
wchar_t c = L'a';
|
wchar_t c = L'a';
|
||||||
int res = str.compare(0, 1, &c, 1);
|
int res = str.compare(0, 1, &c, 1);
|
||||||
|
|
|
||||||
|
|
@ -17,23 +17,23 @@
|
||||||
// with this library; see the file COPYING3. If not see
|
// with this library; see the file COPYING3. If not see
|
||||||
// <http://www.gnu.org/licenses/>.
|
// <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
#include <string>
|
#include <testsuite_string.h>
|
||||||
#include <testsuite_hooks.h>
|
#include <testsuite_hooks.h>
|
||||||
|
|
||||||
// 21.3.6.2 basic_string rfind
|
// 21.3.6.2 basic_string rfind
|
||||||
void test01(void)
|
void test01(void)
|
||||||
{
|
{
|
||||||
typedef std::string::size_type csize_type;
|
typedef __gnu_test::string::size_type csize_type;
|
||||||
typedef std::string::const_reference cref;
|
typedef __gnu_test::string::const_reference cref;
|
||||||
typedef std::string::reference ref;
|
typedef __gnu_test::string::reference ref;
|
||||||
csize_type npos = std::string::npos;
|
csize_type npos = __gnu_test::string::npos;
|
||||||
csize_type csz01, csz02;
|
csize_type csz01, csz02;
|
||||||
|
|
||||||
const char str_lit01[] = "mave";
|
const char str_lit01[] = "mave";
|
||||||
const std::string str01("mavericks, santa cruz");
|
const __gnu_test::string str01("mavericks, santa cruz");
|
||||||
std::string str02(str_lit01);
|
__gnu_test::string str02(str_lit01);
|
||||||
std::string str03("s, s");
|
__gnu_test::string str03("s, s");
|
||||||
std::string str04;
|
__gnu_test::string str04;
|
||||||
|
|
||||||
// size_type rfind(const string&, size_type pos = 0) const;
|
// size_type rfind(const string&, size_type pos = 0) const;
|
||||||
csz01 = str01.rfind(str01);
|
csz01 = str01.rfind(str01);
|
||||||
|
|
|
||||||
|
|
@ -17,14 +17,14 @@
|
||||||
// with this library; see the file COPYING3. If not see
|
// with this library; see the file COPYING3. If not see
|
||||||
// <http://www.gnu.org/licenses/>.
|
// <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
#include <string>
|
#include <testsuite_string.h>
|
||||||
#include <testsuite_hooks.h>
|
#include <testsuite_hooks.h>
|
||||||
|
|
||||||
// 21.3.6.4 basic_string::find_last_of
|
// 21.3.6.4 basic_string::find_last_of
|
||||||
void test02()
|
void test02()
|
||||||
{
|
{
|
||||||
std::string z("ab");
|
__gnu_test::string z("ab");
|
||||||
std::string::size_type pos;
|
__gnu_test::string::size_type pos;
|
||||||
pos = z.find_last_of("ab");
|
pos = z.find_last_of("ab");
|
||||||
VERIFY( pos == 1 );
|
VERIFY( pos == 1 );
|
||||||
pos = z.find_last_of("Xa");
|
pos = z.find_last_of("Xa");
|
||||||
|
|
@ -32,13 +32,13 @@ void test02()
|
||||||
pos = z.find_last_of("Xb");
|
pos = z.find_last_of("Xb");
|
||||||
VERIFY( pos == 1 );
|
VERIFY( pos == 1 );
|
||||||
pos = z.find_last_of("XYZ");
|
pos = z.find_last_of("XYZ");
|
||||||
VERIFY( pos == std::string::npos );
|
VERIFY( pos == __gnu_test::string::npos );
|
||||||
pos = z.find_last_of('a');
|
pos = z.find_last_of('a');
|
||||||
VERIFY( pos == 0 );
|
VERIFY( pos == 0 );
|
||||||
pos = z.find_last_of('b');
|
pos = z.find_last_of('b');
|
||||||
VERIFY( pos == 1 );
|
VERIFY( pos == 1 );
|
||||||
pos = z.find_last_of('X');
|
pos = z.find_last_of('X');
|
||||||
VERIFY( pos == std::string::npos );
|
VERIFY( pos == __gnu_test::string::npos );
|
||||||
}
|
}
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
|
|
|
||||||
|
|
@ -17,23 +17,23 @@
|
||||||
// with this library; see the file COPYING3. If not see
|
// with this library; see the file COPYING3. If not see
|
||||||
// <http://www.gnu.org/licenses/>.
|
// <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
#include <string>
|
#include <testsuite_string.h>
|
||||||
#include <testsuite_hooks.h>
|
#include <testsuite_hooks.h>
|
||||||
|
|
||||||
// 21.3.6.6 basic_string::find_last_not_of
|
// 21.3.6.6 basic_string::find_last_not_of
|
||||||
void test03()
|
void test03()
|
||||||
{
|
{
|
||||||
typedef std::string::size_type csize_type;
|
typedef __gnu_test::string::size_type csize_type;
|
||||||
std::string::size_type pos;
|
__gnu_test::string::size_type pos;
|
||||||
csize_type npos = std::string::npos;
|
csize_type npos = __gnu_test::string::npos;
|
||||||
|
|
||||||
std::string x;
|
__gnu_test::string x;
|
||||||
pos = x.find_last_not_of('X');
|
pos = x.find_last_not_of('X');
|
||||||
VERIFY( pos == npos );
|
VERIFY( pos == npos );
|
||||||
pos = x.find_last_not_of("XYZ");
|
pos = x.find_last_not_of("XYZ");
|
||||||
VERIFY( pos == npos );
|
VERIFY( pos == npos );
|
||||||
|
|
||||||
std::string y("a");
|
__gnu_test::string y("a");
|
||||||
pos = y.find_last_not_of('X');
|
pos = y.find_last_not_of('X');
|
||||||
VERIFY( pos == 0 );
|
VERIFY( pos == 0 );
|
||||||
pos = y.find_last_not_of('a');
|
pos = y.find_last_not_of('a');
|
||||||
|
|
@ -43,7 +43,7 @@ void test03()
|
||||||
pos = y.find_last_not_of("a");
|
pos = y.find_last_not_of("a");
|
||||||
VERIFY( pos == npos );
|
VERIFY( pos == npos );
|
||||||
|
|
||||||
std::string z("ab");
|
__gnu_test::string z("ab");
|
||||||
pos = z.find_last_not_of('X');
|
pos = z.find_last_not_of('X');
|
||||||
VERIFY( pos == 1 );
|
VERIFY( pos == 1 );
|
||||||
pos = z.find_last_not_of("XYZ");
|
pos = z.find_last_not_of("XYZ");
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
#ifndef _GLIBCXX_TESTSUITE_STRING_H
|
#ifndef _GLIBCXX_TESTSUITE_STRING_H
|
||||||
#define _GLIBCXX_TESTSUITE_STRING_H
|
#define _GLIBCXX_TESTSUITE_STRING_H
|
||||||
|
|
||||||
#ifdef _GLIBCXX_DEBUG
|
#if defined(_GLIBCXX_DEBUG) && defined(_GLIBCXX_TEST_DEBUG_STRING)
|
||||||
# include <debug/string>
|
# include <debug/string>
|
||||||
namespace __gnu_test
|
namespace __gnu_test
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue