This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[v3] libstdc++/3017 revised
- To: gcc-patches at gcc dot gnu dot org
- Subject: [v3] libstdc++/3017 revised
- From: Benjamin Kosnik <bkoz at redhat dot com>
- Date: Mon, 4 Jun 2001 12:28:06 -0700
Ok, added definitions, test case.
2001-06-04 Brendan Kehoe <brendan@zen.org>
Benjamin Kosnik <bkoz@redhat.com>
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.
Index: include/bits/locale_facets.h
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/bits/locale_facets.h,v
retrieving revision 1.13
diff -c -p -r1.13 locale_facets.h
*** locale_facets.h 2001/02/19 18:52:24 1.13
--- locale_facets.h 2001/06/04 19:24:21
*************** namespace std
*** 81,113 ****
{ return this->do_toupper(__c); }
const char_type*
! toupper(char_type *__low, const char_type* __high) const
! { return this->do_toupper(__low, __high); }
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); }
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); }
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,
char __dfault, char *__to) const
! { return this->do_narrow(__low, __high, __dfault, __to); }
protected:
explicit
--- 81,113 ----
{ return this->do_toupper(__c); }
const char_type*
! 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* __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* __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* __lo, const char_type* __hi,
char __dfault, char *__to) const
! { return this->do_narrow(__lo, __hi, __dfault, __to); }
protected:
explicit
*************** namespace std
*** 124,130 ****
mask* __vec) const = 0;
virtual const char_type*
! do_scan_is(mask __m, const char_type* __lo,
const char_type* __hi) const = 0;
virtual const char_type*
--- 124,130 ----
mask* __vec) const = 0;
virtual const char_type*
! do_scan_is(mask __m, const char_type* __lo,
const char_type* __hi) const = 0;
virtual const char_type*
*************** namespace std
*** 135,160 ****
do_toupper(char_type) const = 0;
virtual const char_type*
! do_toupper(char_type* __low, const char_type* __high) 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;
virtual char_type
do_widen(char) const = 0;
virtual const char*
! do_widen(const char* __low, const char* __high,
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,
char __dfault, char* __dest) const = 0;
};
--- 135,160 ----
do_toupper(char_type) const = 0;
virtual const char_type*
! 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* __lo, const char_type* __hi) const = 0;
virtual char_type
do_widen(char) const = 0;
virtual const char*
! 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* __lo, const char_type* __hi,
char __dfault, char* __dest) const = 0;
};
*************** namespace std
*** 175,180 ****
--- 175,230 ----
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<typename _CharT>
*************** namespace std
*** 207,219 ****
is(mask __m, char __c) const;
inline const char*
! is(const char* __low, const char* __high, mask* __vec) const;
inline const char*
! scan_is(mask __m, const char* __low, const char* __high) const;
inline const char*
! scan_not(mask __m, const char* __low, const char* __high) const;
protected:
virtual
--- 257,269 ----
is(mask __m, char __c) const;
inline const char*
! is(const char* __lo, const char* __hi, mask* __vec) const;
inline const char*
! scan_is(mask __m, const char* __lo, const char* __hi) const;
inline const char*
! scan_not(mask __m, const char* __lo, const char* __hi) const;
protected:
virtual
*************** namespace std
*** 231,242 ****
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;
virtual const char_type*
! 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,
--- 281,290 ----
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;
virtual const char_type*
! 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,
*************** namespace std
*** 246,271 ****
do_toupper(char_type) const;
virtual const char_type*
! do_toupper(char_type* __low, const char_type* __high) const;
virtual char_type
do_tolower(char_type) const;
virtual const char_type*
! do_tolower(char_type* __low, const char_type* __high) const;
virtual char_type
do_widen(char) const;
virtual const char*
! do_widen(const char* __low, const char* __high,
! 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,
char __dfault, char* __dest) const;
};
--- 294,318 ----
do_toupper(char_type) const;
virtual const char_type*
! 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* __lo, const char_type* __hi) const;
virtual char_type
do_widen(char) const;
virtual const char*
! 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* __lo, const char_type* __hi,
char __dfault, char* __dest) const;
};
*************** namespace std
*** 300,311 ****
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;
virtual const char_type*
! 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,
--- 347,356 ----
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;
virtual const char_type*
! 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,
*************** namespace std
*** 315,340 ****
do_toupper(char_type) const;
virtual const char_type*
! do_toupper(char_type* __low, const char_type* __high) const;
virtual char_type
do_tolower(char_type) const;
virtual const char_type*
! do_tolower(char_type* __low, const char_type* __high) const;
virtual char_type
do_widen(char) const;
virtual const char*
! do_widen(const char* __low, const char* __high,
! 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,
char __dfault, char* __dest) const;
};
--- 360,384 ----
do_toupper(char_type) const;
virtual const char_type*
! 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* __lo, const char_type* __hi) const;
virtual char_type
do_widen(char) const;
virtual const char*
! 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* __lo, const char_type* __hi,
char __dfault, char* __dest) const;
};
Index: src/locale.cc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/src/locale.cc,v
retrieving revision 1.32
diff -c -p -r1.32 locale.cc
*** locale.cc 2001/05/08 03:07:56 1.32
--- locale.cc 2001/06/04 19:24:23
*************** namespace std
*** 583,593 ****
{ return __c; }
const char*
! ctype<char>::do_widen(const char* __low, const char* __high,
! char* __dest) const
{
! memcpy(__dest, __low, __high - __low);
! return __high;
}
char
--- 583,592 ----
{ return __c; }
const char*
! ctype<char>::do_widen(const char* __lo, const char* __hi, char* __dest) const
{
! memcpy(__dest, __lo, __hi - __lo);
! return __hi;
}
char
*************** namespace std
*** 595,605 ****
{ return __c; }
const char*
! ctype<char>::do_narrow(const char* __low, const char* __high,
char /*__dfault*/, char* __dest) const
{
! memcpy(__dest, __low, __high - __low);
! return __high;
}
ctype_byname<char>::ctype_byname(const char* /*__s*/, size_t __refs)
--- 594,604 ----
{ return __c; }
const char*
! ctype<char>::do_narrow(const char* __lo, const char* __hi,
char /*__dfault*/, char* __dest) const
{
! memcpy(__dest, __lo, __hi - __lo);
! return __hi;
}
ctype_byname<char>::ctype_byname(const char* /*__s*/, size_t __refs)
*************** namespace std
*** 1110,1123 ****
{ return towupper(__c); }
const wchar_t*
! ctype<wchar_t>::do_toupper(wchar_t* __low, const wchar_t* __high) const
{
! while (__low < __high)
{
! *__low = towupper(*__low);
! ++__low;
}
! return __high;
}
wchar_t
--- 1109,1122 ----
{ return towupper(__c); }
const wchar_t*
! ctype<wchar_t>::do_toupper(wchar_t* __lo, const wchar_t* __hi) const
{
! while (__lo < __hi)
{
! *__lo = towupper(*__lo);
! ++__lo;
}
! return __hi;
}
wchar_t
*************** namespace std
*** 1125,1138 ****
{ return towlower(__c); }
const wchar_t*
! ctype<wchar_t>::do_tolower(wchar_t* __low, const wchar_t* __high) const
{
! while (__low < __high)
{
! *__low = towlower(*__low);
! ++__low;
}
! return __high;
}
bool
--- 1124,1137 ----
{ return towlower(__c); }
const wchar_t*
! ctype<wchar_t>::do_tolower(wchar_t* __lo, const wchar_t* __hi) const
{
! while (__lo < __hi)
{
! *__lo = towlower(*__lo);
! ++__lo;
}
! return __hi;
}
bool
*************** namespace std
*** 1142,1170 ****
const wchar_t*
ctype<wchar_t>::
! do_is(const wchar_t* __low, const wchar_t* __high, mask* __m) const
{
! while (__low < __high && !this->is(*__m, *__low))
! ++__low;
! return __low;
}
const wchar_t*
ctype<wchar_t>::
! do_scan_is(mask __m, const wchar_t* __low, const wchar_t* __high) const
{
! while (__low < __high && !this->is(__m, *__low))
! ++__low;
! return __low;
}
const wchar_t*
ctype<wchar_t>::
! do_scan_not(mask __m, const char_type* __low, const char_type* __high) const
{
! while (__low < __high && this->is(__m, *__low) != 0)
! ++__low;
! return __low;
}
wchar_t
--- 1141,1169 ----
const wchar_t*
ctype<wchar_t>::
! do_is(const wchar_t* __lo, const wchar_t* __hi, mask* __m) const
{
! while (__lo < __hi && !this->is(*__m, *__lo))
! ++__lo;
! return __lo;
}
const wchar_t*
ctype<wchar_t>::
! do_scan_is(mask __m, const wchar_t* __lo, const wchar_t* __hi) const
{
! while (__lo < __hi && !this->is(__m, *__lo))
! ++__lo;
! return __lo;
}
const wchar_t*
ctype<wchar_t>::
! do_scan_not(mask __m, const char_type* __lo, const char_type* __hi) const
{
! while (__lo < __hi && this->is(__m, *__lo) != 0)
! ++__lo;
! return __lo;
}
wchar_t
*************** namespace std
*** 1174,1185 ****
const char*
ctype<wchar_t>::
! do_widen(const char* __low, const char* __high, wchar_t* __dest) const
{
mbstate_t __state;
memset(static_cast<void*>(&__state), 0, sizeof(mbstate_t));
! mbsrtowcs(__dest, &__low, __high - __low, &__state);
! return __high;
}
char
--- 1173,1184 ----
const char*
ctype<wchar_t>::
! do_widen(const char* __lo, const char* __hi, wchar_t* __dest) const
{
mbstate_t __state;
memset(static_cast<void*>(&__state), 0, sizeof(mbstate_t));
! mbsrtowcs(__dest, &__lo, __hi - __lo, &__state);
! return __hi;
}
char
*************** namespace std
*** 1192,1207 ****
const wchar_t*
ctype<wchar_t>::
! do_narrow(const wchar_t* __low, const wchar_t* __high, char __dfault,
char* __dest) const
{
mbstate_t __state;
memset(static_cast<void*>(&__state), 0, sizeof(mbstate_t));
! size_t __len = __high - __low;
! size_t __conv = wcsrtombs(__dest, &__low, __len, &__state);
if (__conv == __len)
*__dest = __dfault;
! return __high;
}
ctype_byname<wchar_t>::
--- 1191,1206 ----
const wchar_t*
ctype<wchar_t>::
! do_narrow(const wchar_t* __lo, const wchar_t* __hi, char __dfault,
char* __dest) const
{
mbstate_t __state;
memset(static_cast<void*>(&__state), 0, sizeof(mbstate_t));
! size_t __len = __hi - __lo;
! size_t __conv = wcsrtombs(__dest, &__lo, __len, &__state);
if (__conv == __len)
*__dest = __dfault;
! return __hi;
}
ctype_byname<wchar_t>::
Index: testsuite/22_locale/ctype.cc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/testsuite/22_locale/ctype.cc,v
retrieving revision 1.3
diff -c -p -r1.3 ctype.cc
*** ctype.cc 2000/12/19 22:55:07 1.3
--- ctype.cc 2001/06/04 19:24:23
*************** test01()
*** 153,160 ****
--- 153,173 ----
m01 ^= m02;
}
+ class gnu_obj
+ { };
+
+ class gnu_ctype2: public std::ctype<gnu_obj>
+ { };
+
+ // libstdc++/3017
+ void test02()
+ {
+ gnu_ctype2 obj;
+ }
+
int main()
{
test01();
+ test02();
return 0;
}