diff -urN libstdc++-v3-orig/include/bits/locale_facets.tcc libstdc++-v3/include/bits/locale_facets.tcc --- libstdc++-v3-orig/include/bits/locale_facets.tcc 2002-09-11 06:25:41.000000000 +0200 +++ libstdc++-v3/include/bits/locale_facets.tcc 2002-09-27 20:31:03.000000000 +0200 @@ -798,8 +798,10 @@ // By itself __add_grouping cannot deal correctly with __ws when // ios::showbase is set and ios_base::oct || ios_base::hex. // Therefore we take care "by hand" of the initial 0, 0x or 0X. + // However, remember that the latter do not occur if the number + // printed is '0' (__len == 1). streamsize __off = 0; - if (__io.flags() & ios_base::showbase) + if ((__io.flags() & ios_base::showbase) && __len > 1) if (__basefield == ios_base::oct) { __off = 1; diff -urN libstdc++-v3-orig/testsuite/22_locale/num_put_members_char.cc libstdc++-v3/testsuite/22_locale/num_put_members_char.cc --- libstdc++-v3-orig/testsuite/22_locale/num_put_members_char.cc 2002-06-21 22:20:57.000000000 +0200 +++ libstdc++-v3/testsuite/22_locale/num_put_members_char.cc 2002-09-27 19:44:47.000000000 +0200 @@ -326,12 +326,50 @@ } } +// Make sure that, in a locale that expects grouping, when showbase +// is true, an hexadecimal or octal zero is correctly output (the case +// of zero is special since there is no 0, 0x respectively, prefix) +void test05() +{ + using namespace std; + bool test = true; + + // A locale that expects grouping. + locale loc_de("de_DE"); + + const string empty; + string result; + + ostringstream oss; + oss.imbue(loc_de); + const num_put& np = use_facet >(oss.getloc()); + + long l = 0; + + oss.str(empty); + oss.clear(); + oss.setf(ios::showbase); + oss.setf(ios::hex, ios::basefield); + np.put(oss.rdbuf(), oss, '+', l); + result = oss.str(); + VERIFY( result == "0" ); + + oss.str(empty); + oss.clear(); + oss.setf(ios::showbase); + oss.setf(ios::oct, ios::basefield); + np.put(oss.rdbuf(), oss, '+', l); + result = oss.str(); + VERIFY( result == "0" ); +} + int main() { test01(); test02(); test03(); test04(); + test05(); return 0; } diff -urN libstdc++-v3-orig/testsuite/22_locale/num_put_members_wchar_t.cc libstdc++-v3/testsuite/22_locale/num_put_members_wchar_t.cc --- libstdc++-v3-orig/testsuite/22_locale/num_put_members_wchar_t.cc 2002-06-21 22:20:57.000000000 +0200 +++ libstdc++-v3/testsuite/22_locale/num_put_members_wchar_t.cc 2002-09-27 19:46:46.000000000 +0200 @@ -325,6 +325,43 @@ VERIFY( preLANG == postLANG ); } } + +// Make sure that, in a locale that expects grouping, when showbase +// is true, an hexadecimal or octal zero is correctly output (the case +// of zero is special since there is no 0, 0x respectively, prefix) +void test05() +{ + using namespace std; + bool test = true; + + // A locale that expects grouping. + locale loc_de("de_DE"); + + const wstring empty; + wstring result; + + wostringstream oss; + oss.imbue(loc_de); + const num_put& np = use_facet >(oss.getloc()); + + long l = 0; + + oss.str(empty); + oss.clear(); + oss.setf(ios::showbase); + oss.setf(ios::hex, ios::basefield); + np.put(oss.rdbuf(), oss, L'+', l); + result = oss.str(); + VERIFY( result == L"0" ); + + oss.str(empty); + oss.clear(); + oss.setf(ios::showbase); + oss.setf(ios::oct, ios::basefield); + np.put(oss.rdbuf(), oss, L'+', l); + result = oss.str(); + VERIFY( result == L"0" ); +} #endif int main() @@ -334,6 +371,7 @@ test02(); test03(); test04(); + test05(); #endif return 0; }