From 2c64db929411e40009759598a20a0bc1213c2125 Mon Sep 17 00:00:00 2001 From: paolo Date: Sat, 22 May 2004 09:02:56 +0000 Subject: [PATCH] 2004-05-22 Paolo Carlini PR libstdc++/15565 * include/bits/locale_facets.tcc (__int_to_char(unsigned long), __int_to_char(unsigned long long)): Showpos is not relevant for unsigned types. * testsuite/22_locale/num_put/put/char/15565.cc: New. * testsuite/22_locale/num_put/put/wchar_t/15565.cc: New. * testsuite/22_locale/num_put/put/wchar_t/1.cc: Use L for the fill char. * testsuite/22_locale/num_put/put/wchar_t/2.cc: Likewise. * testsuite/22_locale/num_put/put/wchar_t/3.cc: Likewise. * testsuite/22_locale/num_put/put/wchar_t/4.cc: Likewise. * testsuite/22_locale/num_put/put/wchar_t/5.cc: Likewise. * testsuite/22_locale/num_put/put/wchar_t/6.cc: Likewise. * testsuite/22_locale/num_put/put/wchar_t/8.cc: Likewise. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@82128 138bc75d-0d04-0410-961f-82ee72b054a4 --- libstdc++-v3/ChangeLog | 18 +++++++ libstdc++-v3/include/bits/locale_facets.tcc | 12 +++-- .../testsuite/22_locale/num_put/put/char/15565.cc | 63 ++++++++++++++++++++++ .../testsuite/22_locale/num_put/put/wchar_t/1.cc | 24 ++++----- .../22_locale/num_put/put/wchar_t/15565.cc | 63 ++++++++++++++++++++++ .../testsuite/22_locale/num_put/put/wchar_t/2.cc | 10 ++-- .../testsuite/22_locale/num_put/put/wchar_t/3.cc | 6 +-- .../testsuite/22_locale/num_put/put/wchar_t/4.cc | 12 ++--- .../testsuite/22_locale/num_put/put/wchar_t/5.cc | 6 +-- .../testsuite/22_locale/num_put/put/wchar_t/6.cc | 4 +- .../testsuite/22_locale/num_put/put/wchar_t/8.cc | 4 +- 11 files changed, 181 insertions(+), 41 deletions(-) create mode 100644 libstdc++-v3/testsuite/22_locale/num_put/put/char/15565.cc create mode 100644 libstdc++-v3/testsuite/22_locale/num_put/put/wchar_t/15565.cc diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 2080191..a92e408 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,21 @@ +2004-05-22 Paolo Carlini + + PR libstdc++/15565 + * include/bits/locale_facets.tcc (__int_to_char(unsigned long), + __int_to_char(unsigned long long)): Showpos is not relevant + for unsigned types. + * testsuite/22_locale/num_put/put/char/15565.cc: New. + * testsuite/22_locale/num_put/put/wchar_t/15565.cc: New. + + * testsuite/22_locale/num_put/put/wchar_t/1.cc: Use L for the fill + char. + * testsuite/22_locale/num_put/put/wchar_t/2.cc: Likewise. + * testsuite/22_locale/num_put/put/wchar_t/3.cc: Likewise. + * testsuite/22_locale/num_put/put/wchar_t/4.cc: Likewise. + * testsuite/22_locale/num_put/put/wchar_t/5.cc: Likewise. + * testsuite/22_locale/num_put/put/wchar_t/6.cc: Likewise. + * testsuite/22_locale/num_put/put/wchar_t/8.cc: Likewise. + 2004-05-21 Matthias Klose * docs/doxygen/run_doxygen: Bump required version. diff --git a/libstdc++-v3/include/bits/locale_facets.tcc b/libstdc++-v3/include/bits/locale_facets.tcc index 29669b9..ea723fc 100644 --- a/libstdc++-v3/include/bits/locale_facets.tcc +++ b/libstdc++-v3/include/bits/locale_facets.tcc @@ -497,7 +497,8 @@ namespace std // At this point, base is determined. If not hex, only allow // base digits as valid input. - const size_t __len = __base == 16 ? __num_base::_S_iend - __num_base::_S_izero : __base; + const size_t __len = (__base == 16 ? __num_base::_S_iend + - __num_base::_S_izero : __base); // Extract. string __found_grouping; @@ -826,7 +827,11 @@ namespace std inline int __int_to_char(_CharT* __bufend, unsigned long __v, const _CharT* __lit, ios_base::fmtflags __flags) - { return __int_to_char(__bufend, __v, __lit, __flags, false); } + { + // About showpos, see Table 60 and C99 7.19.6.1, p6 (+). + return __int_to_char(__bufend, __v, __lit, + __flags & ~ios_base::showpos, false); + } #ifdef _GLIBCXX_USE_LONG_LONG template @@ -848,7 +853,8 @@ namespace std inline int __int_to_char(_CharT* __bufend, unsigned long long __v, const _CharT* __lit, ios_base::fmtflags __flags) - { return __int_to_char(__bufend, __v, __lit, __flags, false); } + { return __int_to_char(__bufend, __v, __lit, + __flags & ~ios_base::showpos, false); } #endif template diff --git a/libstdc++-v3/testsuite/22_locale/num_put/put/char/15565.cc b/libstdc++-v3/testsuite/22_locale/num_put/put/char/15565.cc new file mode 100644 index 0000000..a62ab1e --- /dev/null +++ b/libstdc++-v3/testsuite/22_locale/num_put/put/char/15565.cc @@ -0,0 +1,63 @@ +// Copyright (C) 2004 Free Software Foundation +// +// 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 2, 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 COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 22.2.2.2.1 num_put members + +#include +#include +#include + +// libstdc++/15565 +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + // basic construction + locale loc_c = locale::classic(); + + // sanity check the data is correct. + const string empty; + + // cache the num_put facet + ostringstream oss; + oss.imbue(loc_c); + const num_put& np = use_facet >(oss.getloc()); + + unsigned long ul1 = 42UL; + oss.str(empty); + oss.clear(); + oss.setf(ios_base::showpos); + np.put(oss.rdbuf(), oss, ' ', ul1); + VERIFY( oss.str() == "42" ); + +#ifdef _GLIBCXX_USE_LONG_LONG + unsigned long long ull1 = 31ULL; + oss.str(empty); + oss.clear(); + oss.setf(ios_base::showpos); + np.put(oss.rdbuf(), oss, ' ', ull1); + VERIFY( oss.str() == "31" ); +#endif +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/22_locale/num_put/put/wchar_t/1.cc b/libstdc++-v3/testsuite/22_locale/num_put/put/wchar_t/1.cc index 50721e9..efc0f51 100644 --- a/libstdc++-v3/testsuite/22_locale/num_put/put/wchar_t/1.cc +++ b/libstdc++-v3/testsuite/22_locale/num_put/put/wchar_t/1.cc @@ -60,13 +60,13 @@ void test01() // bool, simple iterator_type os_it00 = oss.rdbuf(); - iterator_type os_it01 = np.put(os_it00, oss, '+', b1); + iterator_type os_it01 = np.put(os_it00, oss, L'+', b1); result1 = oss.str(); VERIFY( result1 == L"1" ); // VERIFY( os_it00 != os_it01 ); oss.str(empty); - np.put(oss.rdbuf(), oss, '+', b0); + np.put(oss.rdbuf(), oss, L'+', b0); result2 = oss.str(); VERIFY( result2 == L"0" ); @@ -76,7 +76,7 @@ void test01() oss.clear(); oss.width(20); oss.setf(ios_base::left, ios_base::adjustfield); - np.put(oss.rdbuf(), oss, '+', ul1); + np.put(oss.rdbuf(), oss, L'+', ul1); result1 = oss.str(); VERIFY( result1 == L"1.294.967.294+++++++" ); @@ -85,7 +85,7 @@ void test01() oss.clear(); oss.width(20); oss.setf(ios_base::left, ios_base::adjustfield); - np.put(oss.rdbuf(), oss, '+', d1); + np.put(oss.rdbuf(), oss, L'+', d1); result1 = oss.str(); VERIFY( result1 == L"1,79769e+308++++++++" ); @@ -93,7 +93,7 @@ void test01() oss.clear(); oss.width(20); oss.setf(ios_base::right, ios_base::adjustfield); - np.put(oss.rdbuf(), oss, '+', d2); + np.put(oss.rdbuf(), oss, L'+', d2); result1 = oss.str(); VERIFY( result1 == L"++++++++2,22507e-308" ); @@ -102,7 +102,7 @@ void test01() oss.width(20); oss.setf(ios_base::right, ios_base::adjustfield); oss.setf(ios_base::scientific, ios_base::floatfield); - np.put(oss.rdbuf(), oss, '+', d2); + np.put(oss.rdbuf(), oss, L'+', d2); result2 = oss.str(); VERIFY( result2 == L"+++++++2,225074e-308" ); @@ -113,14 +113,14 @@ void test01() oss.setf(ios_base::right, ios_base::adjustfield); oss.setf(ios_base::scientific, ios_base::floatfield); oss.setf(ios_base::uppercase); - np.put(oss.rdbuf(), oss, '+', d2); + np.put(oss.rdbuf(), oss, L'+', d2); result1 = oss.str(); VERIFY( result1 == L"+++2,2250738585E-308" ); // long double oss.str(empty); oss.clear(); - np.put(oss.rdbuf(), oss, '+', ld1); + np.put(oss.rdbuf(), oss, L'+', ld1); result1 = oss.str(); VERIFY( result1 == L"1,7976931349E+308" ); @@ -128,14 +128,14 @@ void test01() oss.clear(); oss.precision(0); oss.setf(ios_base::fixed, ios_base::floatfield); - np.put(oss.rdbuf(), oss, '+', ld2); + np.put(oss.rdbuf(), oss, L'+', ld2); result1 = oss.str(); VERIFY( result1 == L"0" ); // const void oss.str(empty); oss.clear(); - np.put(oss.rdbuf(), oss, '+', cv); + np.put(oss.rdbuf(), oss, L'+', cv); result1 = oss.str(); // No grouping characters. VERIFY( !char_traits::find(result1.c_str(), @@ -149,7 +149,7 @@ void test01() oss.str(empty); oss.clear(); - np.put(oss.rdbuf(), oss, '+', ll1); + np.put(oss.rdbuf(), oss, L'+', ll1); result1 = oss.str(); VERIFY( result1 == L"9.223.372.036.854.775.807" ); #endif @@ -160,5 +160,3 @@ int main() test01(); return 0; } - - diff --git a/libstdc++-v3/testsuite/22_locale/num_put/put/wchar_t/15565.cc b/libstdc++-v3/testsuite/22_locale/num_put/put/wchar_t/15565.cc new file mode 100644 index 0000000..d61a442 --- /dev/null +++ b/libstdc++-v3/testsuite/22_locale/num_put/put/wchar_t/15565.cc @@ -0,0 +1,63 @@ +// Copyright (C) 2004 Free Software Foundation +// +// 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 2, 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 COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 22.2.2.2.1 num_put members + +#include +#include +#include + +// libstdc++/15565 +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + // basic construction + locale loc_c = locale::classic(); + + // sanity check the data is correct. + const wstring empty; + + // cache the num_put facet + wostringstream oss; + oss.imbue(loc_c); + const num_put& np = use_facet >(oss.getloc()); + + unsigned long ul1 = 42UL; + oss.str(empty); + oss.clear(); + oss.setf(ios_base::showpos); + np.put(oss.rdbuf(), oss, L' ', ul1); + VERIFY( oss.str() == L"42" ); + +#ifdef _GLIBCXX_USE_LONG_LONG + unsigned long long ull1 = 31ULL; + oss.str(empty); + oss.clear(); + oss.setf(ios_base::showpos); + np.put(oss.rdbuf(), oss, L' ', ull1); + VERIFY( oss.str() == L"31" ); +#endif +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/22_locale/num_put/put/wchar_t/2.cc b/libstdc++-v3/testsuite/22_locale/num_put/put/wchar_t/2.cc index 7be4cd7..f32351d 100644 --- a/libstdc++-v3/testsuite/22_locale/num_put/put/wchar_t/2.cc +++ b/libstdc++-v3/testsuite/22_locale/num_put/put/wchar_t/2.cc @@ -54,7 +54,7 @@ void test02() oss.str(empty); oss.width(20); oss.setf(ios_base::right, ios_base::adjustfield); - np.put(oss.rdbuf(), oss, '+', b0); + np.put(oss.rdbuf(), oss, L'+', b0); result1 = oss.str(); VERIFY( result1 == L"+++++++++++++++++++0" ); @@ -62,7 +62,7 @@ void test02() oss.width(20); oss.setf(ios_base::left, ios_base::adjustfield); oss.setf(ios_base::boolalpha); - np.put(oss.rdbuf(), oss, '+', b1); + np.put(oss.rdbuf(), oss, L'+', b1); result2 = oss.str(); VERIFY( result2 == L"true++++++++++++++++" ); @@ -70,7 +70,7 @@ void test02() oss.imbue(loc_c); oss.str(empty); oss.clear(); - np.put(oss.rdbuf(), oss, '+', ul1); + np.put(oss.rdbuf(), oss, L'+', ul1); result1 = oss.str(); VERIFY( result1 == L"1294967294" ); @@ -78,7 +78,7 @@ void test02() oss.clear(); oss.width(20); oss.setf(ios_base::left, ios_base::adjustfield); - np.put(oss.rdbuf(), oss, '+', ul2); + np.put(oss.rdbuf(), oss, L'+', ul2); result1 = oss.str(); VERIFY( result1 == L"0+++++++++++++++++++" ); } @@ -88,5 +88,3 @@ int main() test02(); return 0; } - - diff --git a/libstdc++-v3/testsuite/22_locale/num_put/put/wchar_t/3.cc b/libstdc++-v3/testsuite/22_locale/num_put/put/wchar_t/3.cc index 0c75c79..6a96202 100644 --- a/libstdc++-v3/testsuite/22_locale/num_put/put/wchar_t/3.cc +++ b/libstdc++-v3/testsuite/22_locale/num_put/put/wchar_t/3.cc @@ -53,7 +53,7 @@ void test03() // long, in a locale that expects grouping oss.str(empty); oss.clear(); - np.put(oss.rdbuf(), oss, '+', l1); + np.put(oss.rdbuf(), oss, L'+', l1); result1 = oss.str(); VERIFY( result1 == L"2,147,483,647" ); @@ -61,7 +61,7 @@ void test03() oss.clear(); oss.width(20); oss.setf(ios_base::left, ios_base::adjustfield); - np.put(oss.rdbuf(), oss, '+', l2); + np.put(oss.rdbuf(), oss, L'+', l2); result1 = oss.str(); VERIFY( result1 == L"-2,147,483,647++++++" ); } @@ -71,5 +71,3 @@ int main() test03(); return 0; } - - diff --git a/libstdc++-v3/testsuite/22_locale/num_put/put/wchar_t/4.cc b/libstdc++-v3/testsuite/22_locale/num_put/put/wchar_t/4.cc index 5de209f..69a69f1 100644 --- a/libstdc++-v3/testsuite/22_locale/num_put/put/wchar_t/4.cc +++ b/libstdc++-v3/testsuite/22_locale/num_put/put/wchar_t/4.cc @@ -53,7 +53,7 @@ void test04() // 01 put(long) const long l = 1798; res = x; - iter_type ret1 = tp.put(res.begin(), oss, ' ', l); + iter_type ret1 = tp.put(res.begin(), oss, L' ', l); wstring sanity1(res.begin(), ret1); VERIFY( res == L"1798xxxxxxxxxxxxxx" ); VERIFY( sanity1 == L"1798" ); @@ -61,7 +61,7 @@ void test04() // 02 put(long double) const long double ld = 1798.0; res = x; - iter_type ret2 = tp.put(res.begin(), oss, ' ', ld); + iter_type ret2 = tp.put(res.begin(), oss, L' ', ld); wstring sanity2(res.begin(), ret2); VERIFY( res == L"1798xxxxxxxxxxxxxx" ); VERIFY( sanity2 == L"1798" ); @@ -69,7 +69,7 @@ void test04() // 03 put(bool) bool b = 1; res = x; - iter_type ret3 = tp.put(res.begin(), oss, ' ', b); + iter_type ret3 = tp.put(res.begin(), oss, L' ', b); wstring sanity3(res.begin(), ret3); VERIFY( res == L"1xxxxxxxxxxxxxxxxx" ); VERIFY( sanity3 == L"1" ); @@ -77,7 +77,7 @@ void test04() b = 0; res = x; oss.setf(ios_base::boolalpha); - iter_type ret4 = tp.put(res.begin(), oss, ' ', b); + iter_type ret4 = tp.put(res.begin(), oss, L' ', b); wstring sanity4(res.begin(), ret4); VERIFY( res == L"falsexxxxxxxxxxxxx" ); VERIFY( sanity4 == L"false" ); @@ -87,7 +87,7 @@ void test04() const void* cv = &ld; res = x; oss.setf(ios_base::fixed, ios_base::floatfield); - iter_type ret5 = tp.put(res.begin(), oss, ' ', cv); + iter_type ret5 = tp.put(res.begin(), oss, L' ', cv); wstring sanity5(res.begin(), ret5); VERIFY( sanity5.size() ); VERIFY( sanity5[1] == L'x' ); @@ -98,5 +98,3 @@ int main() test04(); return 0; } - - diff --git a/libstdc++-v3/testsuite/22_locale/num_put/put/wchar_t/5.cc b/libstdc++-v3/testsuite/22_locale/num_put/put/wchar_t/5.cc index 51bcbff..8107aa1 100644 --- a/libstdc++-v3/testsuite/22_locale/num_put/put/wchar_t/5.cc +++ b/libstdc++-v3/testsuite/22_locale/num_put/put/wchar_t/5.cc @@ -48,7 +48,7 @@ void test05() oss.clear(); oss.setf(ios::showbase); oss.setf(ios::hex, ios::basefield); - np.put(oss.rdbuf(), oss, '+', l); + np.put(oss.rdbuf(), oss, L'+', l); result = oss.str(); VERIFY( result == L"0" ); @@ -56,7 +56,7 @@ void test05() oss.clear(); oss.setf(ios::showbase); oss.setf(ios::oct, ios::basefield); - np.put(oss.rdbuf(), oss, '+', l); + np.put(oss.rdbuf(), oss, L'+', l); result = oss.str(); VERIFY( result == L"0" ); } @@ -66,5 +66,3 @@ int main() test05(); return 0; } - - diff --git a/libstdc++-v3/testsuite/22_locale/num_put/put/wchar_t/6.cc b/libstdc++-v3/testsuite/22_locale/num_put/put/wchar_t/6.cc index 88ceb0d..f324ca3 100644 --- a/libstdc++-v3/testsuite/22_locale/num_put/put/wchar_t/6.cc +++ b/libstdc++-v3/testsuite/22_locale/num_put/put/wchar_t/6.cc @@ -38,13 +38,13 @@ void test01() woss1.precision(-1); woss1.setf(ios_base::fixed, ios_base::floatfield); - np1.put(woss1.rdbuf(), woss1, '+', 30.5); + np1.put(woss1.rdbuf(), woss1, L'+', 30.5); result1 = woss1.str(); VERIFY( result1 == L"30.500000" ); woss2.precision(0); woss2.setf(ios_base::scientific, ios_base::floatfield); - np2.put(woss2.rdbuf(), woss2, '+', 1.0); + np2.put(woss2.rdbuf(), woss2, L'+', 1.0); result2 = woss2.str(); VERIFY( result2 == L"1e+00" ); } diff --git a/libstdc++-v3/testsuite/22_locale/num_put/put/wchar_t/8.cc b/libstdc++-v3/testsuite/22_locale/num_put/put/wchar_t/8.cc index b1915d4..a1efe66 100644 --- a/libstdc++-v3/testsuite/22_locale/num_put/put/wchar_t/8.cc +++ b/libstdc++-v3/testsuite/22_locale/num_put/put/wchar_t/8.cc @@ -51,13 +51,13 @@ void test01() long inum = 123; double fnum = 123.456; - np.put(oss.rdbuf(), oss, '+', inum); + np.put(oss.rdbuf(), oss, L'+', inum); result = oss.str(); VERIFY( result == L"XYZ" ); oss.clear(); oss.str(empty); - np.put(oss.rdbuf(), oss, '+', fnum); + np.put(oss.rdbuf(), oss, L'+', fnum); result = oss.str(); VERIFY( result == L"XYZ.ABC" ); } -- 2.7.4