From: Benjamin Kosnik Date: Wed, 13 Mar 2002 02:32:08 +0000 (+0000) Subject: ctype_noninline.h: Cast to unsigned char. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=f714575791328145af8d338ebca8dfb224ba7235;p=gcc.git ctype_noninline.h: Cast to unsigned char. 2002-03-12 Benjamin Kosnik Per Liboriussen * config/os/gnu-linux/bits/ctype_noninline.h: Cast to unsigned char. * config/os/gnu-linux/bits/ctype_inline.h: Same. * config/os/irix/irix6.5/bits/ctype_inline.h: Same. * config/os/solaris/solaris2.5/bits/ctype_inline.h: Same. * config/os/solaris/solaris2.5/bits/ctype_noninline.h: Same. * config/os/solaris/solaris2.6/bits/ctype_inline.h: Same. * config/os/solaris/solaris2.6/bits/ctype_noninline.h: Same. * config/os/solaris/solaris2.7/bits/ctype_inline.h: Same. * config/os/solaris/solaris2.7/bits/ctype_noninline.h: Same. * testsuite/22_locale/ctype_members_char.cc (main): Add tests. Co-Authored-By: Per Liboriussen From-SVN: r50708 --- diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 9e07ffd9419..c055900584e 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,23 @@ +2002-03-12 Benjamin Kosnik + Per Liboriussen + + * config/os/gnu-linux/bits/ctype_noninline.h: Cast to + unsigned char. + * config/os/gnu-linux/bits/ctype_inline.h: Same. + + * config/os/irix/irix6.5/bits/ctype_inline.h: Same. + + * config/os/solaris/solaris2.5/bits/ctype_inline.h: Same. + * config/os/solaris/solaris2.5/bits/ctype_noninline.h: Same. + + * config/os/solaris/solaris2.6/bits/ctype_inline.h: Same. + * config/os/solaris/solaris2.6/bits/ctype_noninline.h: Same. + + * config/os/solaris/solaris2.7/bits/ctype_inline.h: Same. + * config/os/solaris/solaris2.7/bits/ctype_noninline.h: Same. + + * testsuite/22_locale/ctype_members_char.cc (main): Add tests. + 2002-03-12 Benjamin Kosnik * include/bits/basic_string.tcc (string::_S_construct(_InIter, diff --git a/libstdc++-v3/config/os/gnu-linux/bits/ctype_inline.h b/libstdc++-v3/config/os/gnu-linux/bits/ctype_inline.h index e584083a1d4..af409c87629 100644 --- a/libstdc++-v3/config/os/gnu-linux/bits/ctype_inline.h +++ b/libstdc++-v3/config/os/gnu-linux/bits/ctype_inline.h @@ -1,6 +1,6 @@ // Locale support -*- C++ -*- -// Copyright (C) 2000 Free Software Foundation, Inc. +// Copyright (C) 2000, 2002 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 @@ -37,14 +37,14 @@ bool ctype:: is(mask __m, char __c) const - { return _M_table[__c] & __m; } + { return _M_table[static_cast(__c)] & __m; } const char* ctype:: is(const char* __low, const char* __high, mask* __vec) const { while (__low < __high) - *__vec++ = _M_table[*__low++]; + *__vec++ = _M_table[static_cast(*__low++)]; return __high; } @@ -52,7 +52,8 @@ ctype:: scan_is(mask __m, const char* __low, const char* __high) const { - while (__low < __high && !(_M_table[*__low] & __m)) + while (__low < __high + && !(_M_table[static_cast(*__low)] & __m)) ++__low; return __low; } @@ -61,7 +62,8 @@ ctype:: scan_not(mask __m, const char* __low, const char* __high) const { - while (__low < __high && (_M_table[*__low] & __m) != 0) + while (__low < __high + && (_M_table[static_cast(*__low)] & __m) != 0) ++__low; return __low; } diff --git a/libstdc++-v3/config/os/gnu-linux/bits/ctype_noninline.h b/libstdc++-v3/config/os/gnu-linux/bits/ctype_noninline.h index 86a38fa8f58..18324d167dd 100644 --- a/libstdc++-v3/config/os/gnu-linux/bits/ctype_noninline.h +++ b/libstdc++-v3/config/os/gnu-linux/bits/ctype_noninline.h @@ -71,14 +71,14 @@ char ctype::do_toupper(char __c) const - { return _M_toupper[static_cast(__c)]; } + { return _M_toupper[static_cast(__c)]; } const char* ctype::do_toupper(char* __low, const char* __high) const { while (__low < __high) { - *__low = _M_toupper[static_cast(*__low)]; + *__low = _M_toupper[static_cast(*__low)]; ++__low; } return __high; @@ -86,14 +86,14 @@ char ctype::do_tolower(char __c) const - { return _M_tolower[static_cast(__c)]; } + { return _M_tolower[static_cast(__c)]; } const char* ctype::do_tolower(char* __low, const char* __high) const { while (__low < __high) { - *__low = _M_tolower[static_cast(*__low)]; + *__low = _M_tolower[static_cast(*__low)]; ++__low; } return __high; diff --git a/libstdc++-v3/config/os/irix/irix6.5/bits/ctype_inline.h b/libstdc++-v3/config/os/irix/irix6.5/bits/ctype_inline.h index 6a20c096cd5..b7ab12dbf14 100644 --- a/libstdc++-v3/config/os/irix/irix6.5/bits/ctype_inline.h +++ b/libstdc++-v3/config/os/irix/irix6.5/bits/ctype_inline.h @@ -1,6 +1,6 @@ // Locale support -*- C++ -*- -// Copyright (C) 2000 Free Software Foundation, Inc. +// Copyright (C) 2000, 2002 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 @@ -37,14 +37,14 @@ bool ctype:: is(mask __m, char __c) const - { return (_M_table)[__c] & __m; } + { return (_M_table)[static_cast(__c)] & __m; } const char* ctype:: is(const char* __low, const char* __high, mask* __vec) const { while (__low < __high) - *__vec++ = (_M_table)[*__low++]; + *__vec++ = (_M_table)[static_cast(*__low++)]; return __high; } @@ -52,7 +52,8 @@ ctype:: scan_is(mask __m, const char* __low, const char* __high) const { - while (__low < __high && !((_M_table)[*__low] & __m)) + while (__low < __high + && !((_M_table)[static_cast(*__low)] & __m)) ++__low; return __low; } @@ -61,12 +62,8 @@ ctype:: scan_not(mask __m, const char* __low, const char* __high) const { - while (__low < __high && ((_M_table + 1)[*__low] & __m) != 0) + while (__low < __high + && ((_M_table + 1)[static_cast(*__low)] & __m) != 0) ++__low; return __low; } - - - - - diff --git a/libstdc++-v3/config/os/solaris/solaris2.5/bits/ctype_inline.h b/libstdc++-v3/config/os/solaris/solaris2.5/bits/ctype_inline.h index affa4945c60..93a04aa1b6d 100644 --- a/libstdc++-v3/config/os/solaris/solaris2.5/bits/ctype_inline.h +++ b/libstdc++-v3/config/os/solaris/solaris2.5/bits/ctype_inline.h @@ -1,6 +1,6 @@ // Locale support -*- C++ -*- -// Copyright (C) 1997-1999, 2000 Free Software Foundation, Inc. +// Copyright (C) 1997-1999, 2000, 2002 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 @@ -37,14 +37,14 @@ bool ctype:: is(mask __m, char __c) const - { return (_M_table + 1)[(unsigned char)(__c)] & __m; } + { return (_M_table + 1)[static_cast(__c)] & __m; } const char* ctype:: is(const char* __low, const char* __high, mask* __vec) const { while (__low < __high) - *__vec++ = (_M_table + 1)[(unsigned char) (*__low++)]; + *__vec++ = (_M_table + 1)[static_cast(*__low++)]; return __high; } @@ -52,7 +52,8 @@ ctype:: scan_is(mask __m, const char* __low, const char* __high) const { - while (__low < __high && !((_M_table + 1)[(unsigned char)(*__low)] & __m)) + while (__low < __high + && !((_M_table + 1)[static_cast(*__low)] & __m)) ++__low; return __low; } @@ -62,7 +63,7 @@ scan_not(mask __m, const char* __low, const char* __high) const { while (__low < __high - && ((_M_table + 1)[(unsigned char)(*__low)] & __m) != 0) + && ((_M_table + 1)[static_cast(*__low)] & __m) != 0) ++__low; return __low; } diff --git a/libstdc++-v3/config/os/solaris/solaris2.5/bits/ctype_noninline.h b/libstdc++-v3/config/os/solaris/solaris2.5/bits/ctype_noninline.h index 9ab764a6c17..f466afbc1ce 100644 --- a/libstdc++-v3/config/os/solaris/solaris2.5/bits/ctype_noninline.h +++ b/libstdc++-v3/config/os/solaris/solaris2.5/bits/ctype_noninline.h @@ -52,7 +52,7 @@ char ctype::do_toupper(char __c) const - { return ((_M_table + 258)[static_cast(__c)]); } + { return ((_M_table + 258)[static_cast(__c)]); } const char* ctype::do_toupper(char* __low, const char* __high) const @@ -67,7 +67,7 @@ char ctype::do_tolower(char __c) const - { return ((_M_table + 258)[static_cast(__c)]); } + { return ((_M_table + 258)[static_cast(__c)]); } const char* ctype::do_tolower(char* __low, const char* __high) const @@ -79,5 +79,3 @@ } return __high; } - - diff --git a/libstdc++-v3/config/os/solaris/solaris2.6/bits/ctype_inline.h b/libstdc++-v3/config/os/solaris/solaris2.6/bits/ctype_inline.h index f254e839fb8..0bd56a19702 100644 --- a/libstdc++-v3/config/os/solaris/solaris2.6/bits/ctype_inline.h +++ b/libstdc++-v3/config/os/solaris/solaris2.6/bits/ctype_inline.h @@ -1,6 +1,6 @@ // Locale support -*- C++ -*- -// Copyright (C) 2000 Free Software Foundation, Inc. +// Copyright (C) 2000, 2002 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 @@ -37,7 +37,7 @@ bool ctype:: is(mask __m, char __c) const - { return _M_table[__c] & __m; } + { return _M_table[static_cast(__c)] & __m; } const char* ctype:: @@ -46,7 +46,7 @@ const int __bitmasksize = sizeof(mask) * 8; for (;__low < __high; ++__vec, ++__low) { - mask __m = _M_table[*__low]; + mask __m = _M_table[static_cast(*__low)]; int __i = 0; // Lowest bitmask value from ctype_base. while (__i < __bitmasksize && !(__m & static_cast(1 << __i))) ++__i; @@ -59,7 +59,8 @@ ctype:: scan_is(mask __m, const char* __low, const char* __high) const { - while (__low < __high && !(_M_table[*__low] & __m)) + while (__low < __high + && !(_M_table[static_cast(*__low)] & __m)) ++__low; return __low; } @@ -69,7 +70,7 @@ scan_not(mask __m, const char* __low, const char* __high) const { while (__low < __high - && (_M_table[*__low] & __m) != 0) + && (_M_table[static_cast(*__low)] & __m) != 0) ++__low; return __low; } diff --git a/libstdc++-v3/config/os/solaris/solaris2.6/bits/ctype_noninline.h b/libstdc++-v3/config/os/solaris/solaris2.6/bits/ctype_noninline.h index 8e1c2d76f97..b22ad9a1374 100644 --- a/libstdc++-v3/config/os/solaris/solaris2.6/bits/ctype_noninline.h +++ b/libstdc++-v3/config/os/solaris/solaris2.6/bits/ctype_noninline.h @@ -52,14 +52,14 @@ char ctype::do_toupper(char __c) const - { return _M_toupper[(int) __c]; } + { return _M_toupper[static_cast(__c)]; } const char* ctype::do_toupper(char* __low, const char* __high) const { while (__low < __high) { - *__low = _M_toupper[(int) *__low]; + *__low = _M_toupper[static_cast(*__low)]; ++__low; } return __high; @@ -67,14 +67,14 @@ char ctype::do_tolower(char __c) const - { return _M_tolower[(int) __c]; } + { return _M_tolower[static_cast(__c)]; } const char* ctype::do_tolower(char* __low, const char* __high) const { while (__low < __high) { - *__low = _M_tolower[(int) *__low]; + *__low = _M_tolower[static_cast(*__low)]; ++__low; } return __high; diff --git a/libstdc++-v3/config/os/solaris/solaris2.7/bits/ctype_inline.h b/libstdc++-v3/config/os/solaris/solaris2.7/bits/ctype_inline.h index 8ec057dfb47..af409c87629 100644 --- a/libstdc++-v3/config/os/solaris/solaris2.7/bits/ctype_inline.h +++ b/libstdc++-v3/config/os/solaris/solaris2.7/bits/ctype_inline.h @@ -1,6 +1,6 @@ // Locale support -*- C++ -*- -// Copyright (C) 2000 Free Software Foundation, Inc. +// Copyright (C) 2000, 2002 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 @@ -37,14 +37,14 @@ bool ctype:: is(mask __m, char __c) const - { return _M_table[__c] & __m; } + { return _M_table[static_cast(__c)] & __m; } const char* ctype:: is(const char* __low, const char* __high, mask* __vec) const { while (__low < __high) - *__vec++ = _M_table[*__low++]; + *__vec++ = _M_table[static_cast(*__low++)]; return __high; } @@ -52,7 +52,8 @@ ctype:: scan_is(mask __m, const char* __low, const char* __high) const { - while (__low < __high && !(_M_table[*__low] & __m)) + while (__low < __high + && !(_M_table[static_cast(*__low)] & __m)) ++__low; return __low; } @@ -62,7 +63,7 @@ scan_not(mask __m, const char* __low, const char* __high) const { while (__low < __high - && (_M_table[*__low] & __m) != 0) + && (_M_table[static_cast(*__low)] & __m) != 0) ++__low; return __low; } diff --git a/libstdc++-v3/config/os/solaris/solaris2.7/bits/ctype_noninline.h b/libstdc++-v3/config/os/solaris/solaris2.7/bits/ctype_noninline.h index eafc1fc71e2..61462a90945 100644 --- a/libstdc++-v3/config/os/solaris/solaris2.7/bits/ctype_noninline.h +++ b/libstdc++-v3/config/os/solaris/solaris2.7/bits/ctype_noninline.h @@ -53,14 +53,14 @@ char ctype::do_toupper(char __c) const - { return _M_toupper[(int) __c]; } + { return _M_toupper[static_cast(__c)]; } const char* ctype::do_toupper(char* __low, const char* __high) const { while (__low < __high) { - *__low = _M_toupper[(int) *__low]; + *__low = _M_toupper[static_cast(*__low)]; ++__low; } return __high; @@ -68,17 +68,15 @@ char ctype::do_tolower(char __c) const - { return _M_tolower[(int) __c]; } + { return _M_tolower[static_cast(__c)]; } const char* ctype::do_tolower(char* __low, const char* __high) const { while (__low < __high) { - *__low = _M_tolower[(int) *__low]; + *__low = _M_tolower[static_cast(*__low)]; ++__low; } return __high; } - - diff --git a/libstdc++-v3/testsuite/22_locale/ctype_members_char.cc b/libstdc++-v3/testsuite/22_locale/ctype_members_char.cc index cc69094c345..d1e47b6bbbd 100644 --- a/libstdc++-v3/testsuite/22_locale/ctype_members_char.cc +++ b/libstdc++-v3/testsuite/22_locale/ctype_members_char.cc @@ -243,8 +243,25 @@ public: { classic_table(); } }; -// libstdc++/5280 +// Per Liboriussen void test03() +{ + bool test = true; + std::ctype_base::mask maskdata[256]; + for (int i = 0; i < 256; ++i) + maskdata[i] = std::ctype_base::alpha; + std::ctype* f = new std::ctype(maskdata); + std::locale global; + std::locale loc(global, f); + for (int i = 0; i < 256; ++i) + { + char ch = i; + VERIFY( std::isalpha(ch, loc) ); + } +} + +// libstdc++/5280 +void test04() { #ifdef _GLIBCPP_HAVE_SETENV // Set the global locale to non-"C". @@ -257,6 +274,7 @@ void test03() { test01(); test02(); + test03(); setenv("LANG", oldLANG ? oldLANG : "", 1); } #endif @@ -267,5 +285,6 @@ int main() test01(); test02(); test03(); + test04(); return 0; }