From fdf1b60d2b57031da4af9856d0d635bede588bcd Mon Sep 17 00:00:00 2001 From: Benjamin Kosnik Date: Mon, 4 Jun 2001 19:25:41 +0000 Subject: [PATCH] locale_facets.h (ctype<_CharT>): Add definitions for generic ctype virtuals. 2001-06-04 Brendan Kehoe Benjamin Kosnik libstdc++/3017 * include/bits/locale_facets.h (ctype<_CharT>): Add definitions for generic ctype virtuals. * src/locale.cc: Minor tweaks, naming consistency. * testsuite/22_locale/ctype.cc: Add test. From-SVN: r42872 --- libstdc++-v3/ChangeLog | 11 ++- libstdc++-v3/include/bits/locale_facets.h | 112 +++++++++++++++------- libstdc++-v3/src/locale.cc | 71 +++++++------- libstdc++-v3/testsuite/22_locale/ctype.cc | 13 +++ 4 files changed, 136 insertions(+), 71 deletions(-) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index c4828302397..c9bac6cfb18 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,12 @@ +2001-06-04 Brendan Kehoe + Benjamin Kosnik + + libstdc++/3017 + * include/bits/locale_facets.h (ctype<_CharT>): Add definitions + for generic ctype virtuals. + * src/locale.cc: Minor tweaks, naming consistency. + * testsuite/22_locale/ctype.cc: Add test. + 2001-06-04 Kenny Simpson Phil Edwards @@ -57,7 +66,7 @@ make isn't found. * configure: Regenerate. -2001-05-27 scott snyder +2001-05-31 scott snyder libstdc++/2976 * include/bits/istream.tcc: Include std_ostream.h. diff --git a/libstdc++-v3/include/bits/locale_facets.h b/libstdc++-v3/include/bits/locale_facets.h index 2340973669f..cb249f8c51c 100644 --- a/libstdc++-v3/include/bits/locale_facets.h +++ b/libstdc++-v3/include/bits/locale_facets.h @@ -81,33 +81,33 @@ namespace std { return this->do_toupper(__c); } const char_type* - toupper(char_type *__low, const char_type* __high) const - { return this->do_toupper(__low, __high); } + toupper(char_type *__lo, const char_type* __hi) const + { return this->do_toupper(__lo, __hi); } char_type tolower(char_type __c) const { return this->do_tolower(__c); } const char_type* - tolower(char_type* __low, const char_type* __high) const - { return this->do_tolower(__low, __high); } + tolower(char_type* __lo, const char_type* __hi) const + { return this->do_tolower(__lo, __hi); } char_type widen(char __c) const { return this->do_widen(__c); } const char* - widen(const char* __low, const char* __high, char_type* __to) const - { return this->do_widen(__low, __high, __to); } + widen(const char* __lo, const char* __hi, char_type* __to) const + { return this->do_widen(__lo, __hi, __to); } char narrow(char_type __c, char __dfault) const { return this->do_narrow(__c, __dfault); } const char_type* - narrow(const char_type* __low, const char_type* __high, + narrow(const char_type* __lo, const char_type* __hi, char __dfault, char *__to) const - { return this->do_narrow(__low, __high, __dfault, __to); } + { return this->do_narrow(__lo, __hi, __dfault, __to); } protected: explicit @@ -124,7 +124,7 @@ namespace std mask* __vec) const = 0; virtual const char_type* - do_scan_is(mask __m, const char_type* __lo, + do_scan_is(mask __m, const char_type* __lo, const char_type* __hi) const = 0; virtual const char_type* @@ -135,26 +135,26 @@ namespace std do_toupper(char_type) const = 0; virtual const char_type* - do_toupper(char_type* __low, const char_type* __high) const = 0; + do_toupper(char_type* __lo, const char_type* __hi) const = 0; virtual char_type do_tolower(char_type) const = 0; virtual const char_type* - do_tolower(char_type* __low, const char_type* __high) const = 0; + do_tolower(char_type* __lo, const char_type* __hi) const = 0; virtual char_type do_widen(char) const = 0; virtual const char* - do_widen(const char* __low, const char* __high, + do_widen(const char* __lo, const char* __hi, char_type* __dest) const = 0; virtual char do_narrow(char_type, char __dfault) const = 0; virtual const char_type* - do_narrow(const char_type* __low, const char_type* __high, + do_narrow(const char_type* __lo, const char_type* __hi, char __dfault, char* __dest) const = 0; }; @@ -175,6 +175,56 @@ namespace std protected: virtual ~ctype() { } + + virtual bool + do_is(mask __m, char_type __c) const + { return false; } + + virtual const char_type* + do_is(const char_type* __lo, const char_type* __hi, mask* __vec) const + { return __hi; } + + virtual const char_type* + do_scan_is(mask __m, const char_type* __lo, const char_type* __hi) const + { return __hi; } + + virtual const char_type* + do_scan_not(mask __m, const char_type* __lo, + const char_type* __hi) const + { return __hi; } + + virtual char_type + do_toupper(char_type __c) const + { return __c; } + + virtual const char_type* + do_toupper(char_type* __lo, const char_type* __hi) const + { return __hi; } + + virtual char_type + do_tolower(char_type __c) const + { return __c; } + + virtual const char_type* + do_tolower(char_type* __lo, const char_type* __hi) const + { return __hi; } + + virtual char_type + do_widen(char __c) const + { return char_type(); } + + virtual const char* + do_widen(const char* __lo, const char* __hi, char_type* __dest) const + { return __hi; } + + virtual char + do_narrow(char_type, char __dfault) const + { return __dfault; } + + virtual const char_type* + do_narrow(const char_type* __lo, const char_type* __hi, + char __dfault, char* __dest) const + { return __hi; } }; template @@ -207,13 +257,13 @@ namespace std is(mask __m, char __c) const; inline const char* - is(const char* __low, const char* __high, mask* __vec) const; + is(const char* __lo, const char* __hi, mask* __vec) const; inline const char* - scan_is(mask __m, const char* __low, const char* __high) const; + scan_is(mask __m, const char* __lo, const char* __hi) const; inline const char* - scan_not(mask __m, const char* __low, const char* __high) const; + scan_not(mask __m, const char* __lo, const char* __hi) const; protected: virtual @@ -231,12 +281,10 @@ namespace std do_is(mask __m, char_type __c) const; virtual const char_type* - do_is(const char_type* __lo, const char_type* __hi, - mask* __vec) const; + do_is(const char_type* __lo, const char_type* __hi, mask* __vec) const; virtual const char_type* - do_scan_is(mask __m, const char_type* __lo, - const char_type* __hi) const; + do_scan_is(mask __m, const char_type* __lo, const char_type* __hi) const; virtual const char_type* do_scan_not(mask __m, const char_type* __lo, @@ -246,26 +294,25 @@ namespace std do_toupper(char_type) const; virtual const char_type* - do_toupper(char_type* __low, const char_type* __high) const; + do_toupper(char_type* __lo, const char_type* __hi) const; virtual char_type do_tolower(char_type) const; virtual const char_type* - do_tolower(char_type* __low, const char_type* __high) const; + do_tolower(char_type* __lo, const char_type* __hi) const; virtual char_type do_widen(char) const; virtual const char* - do_widen(const char* __low, const char* __high, - char_type* __dest) const; + do_widen(const char* __lo, const char* __hi, char_type* __dest) const; virtual char do_narrow(char_type, char __dfault) const; virtual const char_type* - do_narrow(const char_type* __low, const char_type* __high, + do_narrow(const char_type* __lo, const char_type* __hi, char __dfault, char* __dest) const; }; @@ -300,12 +347,10 @@ namespace std do_is(mask __m, char_type __c) const; virtual const char_type* - do_is(const char_type* __lo, const char_type* __hi, - mask* __vec) const; + do_is(const char_type* __lo, const char_type* __hi, mask* __vec) const; virtual const char_type* - do_scan_is(mask __m, const char_type* __lo, - const char_type* __hi) const; + do_scan_is(mask __m, const char_type* __lo, const char_type* __hi) const; virtual const char_type* do_scan_not(mask __m, const char_type* __lo, @@ -315,26 +360,25 @@ namespace std do_toupper(char_type) const; virtual const char_type* - do_toupper(char_type* __low, const char_type* __high) const; + do_toupper(char_type* __lo, const char_type* __hi) const; virtual char_type do_tolower(char_type) const; virtual const char_type* - do_tolower(char_type* __low, const char_type* __high) const; + do_tolower(char_type* __lo, const char_type* __hi) const; virtual char_type do_widen(char) const; virtual const char* - do_widen(const char* __low, const char* __high, - char_type* __dest) const; + do_widen(const char* __lo, const char* __hi, char_type* __dest) const; virtual char do_narrow(char_type, char __dfault) const; virtual const char_type* - do_narrow(const char_type* __low, const char_type* __high, + do_narrow(const char_type* __lo, const char_type* __hi, char __dfault, char* __dest) const; }; diff --git a/libstdc++-v3/src/locale.cc b/libstdc++-v3/src/locale.cc index 26bbc56da4d..b72d7ffe0b6 100644 --- a/libstdc++-v3/src/locale.cc +++ b/libstdc++-v3/src/locale.cc @@ -583,11 +583,10 @@ namespace std { return __c; } const char* - ctype::do_widen(const char* __low, const char* __high, - char* __dest) const + ctype::do_widen(const char* __lo, const char* __hi, char* __dest) const { - memcpy(__dest, __low, __high - __low); - return __high; + memcpy(__dest, __lo, __hi - __lo); + return __hi; } char @@ -595,11 +594,11 @@ namespace std { return __c; } const char* - ctype::do_narrow(const char* __low, const char* __high, + ctype::do_narrow(const char* __lo, const char* __hi, char /*__dfault*/, char* __dest) const { - memcpy(__dest, __low, __high - __low); - return __high; + memcpy(__dest, __lo, __hi - __lo); + return __hi; } ctype_byname::ctype_byname(const char* /*__s*/, size_t __refs) @@ -1110,14 +1109,14 @@ namespace std { return towupper(__c); } const wchar_t* - ctype::do_toupper(wchar_t* __low, const wchar_t* __high) const + ctype::do_toupper(wchar_t* __lo, const wchar_t* __hi) const { - while (__low < __high) + while (__lo < __hi) { - *__low = towupper(*__low); - ++__low; + *__lo = towupper(*__lo); + ++__lo; } - return __high; + return __hi; } wchar_t @@ -1125,14 +1124,14 @@ namespace std { return towlower(__c); } const wchar_t* - ctype::do_tolower(wchar_t* __low, const wchar_t* __high) const + ctype::do_tolower(wchar_t* __lo, const wchar_t* __hi) const { - while (__low < __high) + while (__lo < __hi) { - *__low = towlower(*__low); - ++__low; + *__lo = towlower(*__lo); + ++__lo; } - return __high; + return __hi; } bool @@ -1142,29 +1141,29 @@ namespace std const wchar_t* ctype:: - do_is(const wchar_t* __low, const wchar_t* __high, mask* __m) const + do_is(const wchar_t* __lo, const wchar_t* __hi, mask* __m) const { - while (__low < __high && !this->is(*__m, *__low)) - ++__low; - return __low; + while (__lo < __hi && !this->is(*__m, *__lo)) + ++__lo; + return __lo; } const wchar_t* ctype:: - do_scan_is(mask __m, const wchar_t* __low, const wchar_t* __high) const + do_scan_is(mask __m, const wchar_t* __lo, const wchar_t* __hi) const { - while (__low < __high && !this->is(__m, *__low)) - ++__low; - return __low; + while (__lo < __hi && !this->is(__m, *__lo)) + ++__lo; + return __lo; } const wchar_t* ctype:: - do_scan_not(mask __m, const char_type* __low, const char_type* __high) const + do_scan_not(mask __m, const char_type* __lo, const char_type* __hi) const { - while (__low < __high && this->is(__m, *__low) != 0) - ++__low; - return __low; + while (__lo < __hi && this->is(__m, *__lo) != 0) + ++__lo; + return __lo; } wchar_t @@ -1174,12 +1173,12 @@ namespace std const char* ctype:: - do_widen(const char* __low, const char* __high, wchar_t* __dest) const + do_widen(const char* __lo, const char* __hi, wchar_t* __dest) const { mbstate_t __state; memset(static_cast(&__state), 0, sizeof(mbstate_t)); - mbsrtowcs(__dest, &__low, __high - __low, &__state); - return __high; + mbsrtowcs(__dest, &__lo, __hi - __lo, &__state); + return __hi; } char @@ -1192,16 +1191,16 @@ namespace std const wchar_t* ctype:: - do_narrow(const wchar_t* __low, const wchar_t* __high, char __dfault, + do_narrow(const wchar_t* __lo, const wchar_t* __hi, char __dfault, char* __dest) const { mbstate_t __state; memset(static_cast(&__state), 0, sizeof(mbstate_t)); - size_t __len = __high - __low; - size_t __conv = wcsrtombs(__dest, &__low, __len, &__state); + size_t __len = __hi - __lo; + size_t __conv = wcsrtombs(__dest, &__lo, __len, &__state); if (__conv == __len) *__dest = __dfault; - return __high; + return __hi; } ctype_byname:: diff --git a/libstdc++-v3/testsuite/22_locale/ctype.cc b/libstdc++-v3/testsuite/22_locale/ctype.cc index b51ee70932b..54a6a4e2e03 100644 --- a/libstdc++-v3/testsuite/22_locale/ctype.cc +++ b/libstdc++-v3/testsuite/22_locale/ctype.cc @@ -153,8 +153,21 @@ test01() m01 ^= m02; } +class gnu_obj +{ }; + +class gnu_ctype2: public std::ctype +{ }; + +// libstdc++/3017 +void test02() +{ + gnu_ctype2 obj; +} + int main() { test01(); + test02(); return 0; } -- 2.30.2