Commit d04e9b7f by Paolo Carlini Committed by Paolo Carlini

re PR libstdc++/22131 (std::num_get fails for input with invalid groups)

2005-06-29  Paolo Carlini  <pcarlini@suse.de>

	PR libstdc++/22131
	* include/bits/locale_facets.tcc (num_get<>::_M_extract_int,
	num_get<>::_M_extract_float, money_get<>::_M_extract):
	Adjust to assign the result also when digit grouping is
	wrong (but the grammar is correct), as per 22.2.2.1.2, p11-12
	(NB: consistently for money_get too).
	* config/locale/generic/c_locale.cc (__convert_from_v): Do
	not check ios_base::failbit at the outset.
	* config/locale/gnu/c_locale.cc: Likewise.
	* testsuite/22_locale/money_get/get/char/22131.cc: New.
	* testsuite/22_locale/money_get/get/wchar_t/22131.cc: Likewise.
	* testsuite/22_locale/num_get/get/char/22131.cc: Likewise.
	* testsuite/22_locale/num_get/get/wchar_t/22131.cc: Likewise.
	* testsuite/22_locale/num_get/get/char/12.cc: Adjust.
	* testsuite/22_locale/num_get/get/wchar_t/12.cc: Likewise.
	* testsuite/27_io/basic_istream/extractors_arithmetic/char/07.cc:
	Likewise.
	* testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/07.cc:
	Likewise.

From-SVN: r101416
parent 43b3a5b1
2005-06-29 Paolo Carlini <pcarlini@suse.de>
PR libstdc++/22131
* include/bits/locale_facets.tcc (num_get<>::_M_extract_int,
num_get<>::_M_extract_float, money_get<>::_M_extract):
Adjust to assign the result also when digit grouping is
wrong (but the grammar is correct), as per 22.2.2.1.2, p11-12
(NB: consistently for money_get too).
* config/locale/generic/c_locale.cc (__convert_from_v): Do
not check ios_base::failbit at the outset.
* config/locale/gnu/c_locale.cc: Likewise.
* testsuite/22_locale/money_get/get/char/22131.cc: New.
* testsuite/22_locale/money_get/get/wchar_t/22131.cc: Likewise.
* testsuite/22_locale/num_get/get/char/22131.cc: Likewise.
* testsuite/22_locale/num_get/get/wchar_t/22131.cc: Likewise.
* testsuite/22_locale/num_get/get/char/12.cc: Adjust.
* testsuite/22_locale/num_get/get/wchar_t/12.cc: Likewise.
* testsuite/27_io/basic_istream/extractors_arithmetic/char/07.cc:
Likewise.
* testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/07.cc:
Likewise.
2005-06-28 Paul Brook <paul@codesourcery.com> 2005-06-28 Paul Brook <paul@codesourcery.com>
* acinclude.m4 (GLIBCXX_ENABLE_SJLJ_EXCEPTIONS): Check for * acinclude.m4 (GLIBCXX_ENABLE_SJLJ_EXCEPTIONS): Check for
......
// Wrapper for underlying C-language localization -*- C++ -*- // Wrapper for underlying C-language localization -*- C++ -*-
// Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc. // Copyright (C) 2001, 2002, 2003, 2004, 2005
// Free Software Foundation, Inc.
// //
// This file is part of the GNU ISO C++ Library. This library is free // 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 // software; you can redistribute it and/or modify it under the
...@@ -50,39 +51,36 @@ namespace std ...@@ -50,39 +51,36 @@ namespace std
__convert_to_v(const char* __s, float& __v, ios_base::iostate& __err, __convert_to_v(const char* __s, float& __v, ios_base::iostate& __err,
const __c_locale&) const __c_locale&)
{ {
if (!(__err & ios_base::failbit)) // Assumes __s formatted for "C" locale.
{ errno = 0;
// Assumes __s formatted for "C" locale. char* __old = strdup(setlocale(LC_ALL, NULL));
char* __old = strdup(setlocale(LC_ALL, NULL)); setlocale(LC_ALL, "C");
setlocale(LC_ALL, "C"); char* __sanity;
char* __sanity;
errno = 0;
#if defined(_GLIBCXX_HAVE_STRTOF) #if defined(_GLIBCXX_HAVE_STRTOF)
float __f = strtof(__s, &__sanity); float __f = strtof(__s, &__sanity);
#else #else
double __d = strtod(__s, &__sanity); double __d = strtod(__s, &__sanity);
float __f = static_cast<float>(__d); float __f = static_cast<float>(__d);
#ifdef _GLIBCXX_HAVE_FINITEF #ifdef _GLIBCXX_HAVE_FINITEF
if (!finitef (__f)) if (!finitef (__f))
errno = ERANGE; errno = ERANGE;
#elif defined (_GLIBCXX_HAVE_FINITE) #elif defined (_GLIBCXX_HAVE_FINITE)
if (!finite (static_cast<double> (__f))) if (!finite (static_cast<double> (__f)))
errno = ERANGE; errno = ERANGE;
#elif defined (_GLIBCXX_HAVE_ISINF) #elif defined (_GLIBCXX_HAVE_ISINF)
if (isinf (static_cast<double> (__f))) if (isinf (static_cast<double> (__f)))
errno = ERANGE; errno = ERANGE;
#else #else
if (fabs(__d) > numeric_limits<float>::max()) if (fabs(__d) > numeric_limits<float>::max())
errno = ERANGE; errno = ERANGE;
#endif #endif
#endif #endif
if (__sanity != __s && errno != ERANGE) if (__sanity != __s && errno != ERANGE)
__v = __f; __v = __f;
else else
__err |= ios_base::failbit; __err |= ios_base::failbit;
setlocale(LC_ALL, __old); setlocale(LC_ALL, __old);
free(__old); free(__old);
}
} }
template<> template<>
...@@ -90,21 +88,18 @@ namespace std ...@@ -90,21 +88,18 @@ namespace std
__convert_to_v(const char* __s, double& __v, ios_base::iostate& __err, __convert_to_v(const char* __s, double& __v, ios_base::iostate& __err,
const __c_locale&) const __c_locale&)
{ {
if (!(__err & ios_base::failbit)) // Assumes __s formatted for "C" locale.
{ errno = 0;
// Assumes __s formatted for "C" locale. char* __old = strdup(setlocale(LC_ALL, NULL));
char* __old = strdup(setlocale(LC_ALL, NULL)); setlocale(LC_ALL, "C");
setlocale(LC_ALL, "C"); char* __sanity;
char* __sanity; double __d = strtod(__s, &__sanity);
errno = 0; if (__sanity != __s && errno != ERANGE)
double __d = strtod(__s, &__sanity); __v = __d;
if (__sanity != __s && errno != ERANGE) else
__v = __d; __err |= ios_base::failbit;
else setlocale(LC_ALL, __old);
__err |= ios_base::failbit; free(__old);
setlocale(LC_ALL, __old);
free(__old);
}
} }
template<> template<>
...@@ -112,31 +107,27 @@ namespace std ...@@ -112,31 +107,27 @@ namespace std
__convert_to_v(const char* __s, long double& __v, __convert_to_v(const char* __s, long double& __v,
ios_base::iostate& __err, const __c_locale&) ios_base::iostate& __err, const __c_locale&)
{ {
if (!(__err & ios_base::failbit)) // Assumes __s formatted for "C" locale.
{ errno = 0;
// Assumes __s formatted for "C" locale. char* __old = strdup(setlocale(LC_ALL, NULL));
char* __old = strdup(setlocale(LC_ALL, NULL)); setlocale(LC_ALL, "C");
setlocale(LC_ALL, "C");
#if defined(_GLIBCXX_HAVE_STRTOLD) #if defined(_GLIBCXX_HAVE_STRTOLD)
char* __sanity; char* __sanity;
errno = 0; long double __ld = strtold(__s, &__sanity);
long double __ld = strtold(__s, &__sanity); if (__sanity != __s && errno != ERANGE)
if (__sanity != __s && errno != ERANGE) __v = __ld;
__v = __ld;
#else #else
typedef char_traits<char>::int_type int_type; typedef char_traits<char>::int_type int_type;
long double __ld; long double __ld;
errno = 0; int __p = sscanf(__s, "%Lf", &__ld);
int __p = sscanf(__s, "%Lf", &__ld); if (__p && static_cast<int_type>(__p) != char_traits<char>::eof()
if (__p && static_cast<int_type>(__p) != char_traits<char>::eof() && errno != ERANGE)
&& errno != ERANGE) __v = __ld;
__v = __ld;
#endif #endif
else else
__err |= ios_base::failbit; __err |= ios_base::failbit;
setlocale(LC_ALL, __old); setlocale(LC_ALL, __old);
free(__old); free(__old);
}
} }
void void
......
// Wrapper for underlying C-language localization -*- C++ -*- // Wrapper for underlying C-language localization -*- C++ -*-
// Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc. // Copyright (C) 2001, 2002, 2003, 2004, 2005
// Free Software Foundation, Inc.
// //
// This file is part of the GNU ISO C++ Library. This library is free // 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 // software; you can redistribute it and/or modify it under the
...@@ -46,16 +47,13 @@ namespace std ...@@ -46,16 +47,13 @@ namespace std
__convert_to_v(const char* __s, float& __v, ios_base::iostate& __err, __convert_to_v(const char* __s, float& __v, ios_base::iostate& __err,
const __c_locale& __cloc) const __c_locale& __cloc)
{ {
if (!(__err & ios_base::failbit)) char* __sanity;
{ errno = 0;
char* __sanity; float __f = __strtof_l(__s, &__sanity, __cloc);
errno = 0; if (__sanity != __s && errno != ERANGE)
float __f = __strtof_l(__s, &__sanity, __cloc); __v = __f;
if (__sanity != __s && errno != ERANGE) else
__v = __f; __err |= ios_base::failbit;
else
__err |= ios_base::failbit;
}
} }
template<> template<>
...@@ -63,16 +61,13 @@ namespace std ...@@ -63,16 +61,13 @@ namespace std
__convert_to_v(const char* __s, double& __v, ios_base::iostate& __err, __convert_to_v(const char* __s, double& __v, ios_base::iostate& __err,
const __c_locale& __cloc) const __c_locale& __cloc)
{ {
if (!(__err & ios_base::failbit)) char* __sanity;
{ errno = 0;
char* __sanity; double __d = __strtod_l(__s, &__sanity, __cloc);
errno = 0; if (__sanity != __s && errno != ERANGE)
double __d = __strtod_l(__s, &__sanity, __cloc); __v = __d;
if (__sanity != __s && errno != ERANGE) else
__v = __d; __err |= ios_base::failbit;
else
__err |= ios_base::failbit;
}
} }
template<> template<>
...@@ -80,16 +75,13 @@ namespace std ...@@ -80,16 +75,13 @@ namespace std
__convert_to_v(const char* __s, long double& __v, ios_base::iostate& __err, __convert_to_v(const char* __s, long double& __v, ios_base::iostate& __err,
const __c_locale& __cloc) const __c_locale& __cloc)
{ {
if (!(__err & ios_base::failbit)) char* __sanity;
{ errno = 0;
char* __sanity; long double __ld = __strtold_l(__s, &__sanity, __cloc);
errno = 0; if (__sanity != __s && errno != ERANGE)
long double __ld = __strtold_l(__s, &__sanity, __cloc); __v = __ld;
if (__sanity != __s && errno != ERANGE) else
__v = __ld; __err |= ios_base::failbit;
else
__err |= ios_base::failbit;
}
} }
void void
......
...@@ -306,6 +306,7 @@ namespace std ...@@ -306,6 +306,7 @@ namespace std
// Next, look for leading zeros. // Next, look for leading zeros.
bool __found_mantissa = false; bool __found_mantissa = false;
int __sep_pos = 0;
while (!__testeof) while (!__testeof)
{ {
if (__lc->_M_use_grouping && __c == __lc->_M_thousands_sep if (__lc->_M_use_grouping && __c == __lc->_M_thousands_sep
...@@ -318,6 +319,8 @@ namespace std ...@@ -318,6 +319,8 @@ namespace std
__xtrc += '0'; __xtrc += '0';
__found_mantissa = true; __found_mantissa = true;
} }
++__sep_pos;
if (++__beg != __end) if (++__beg != __end)
__c = *__beg; __c = *__beg;
else else
...@@ -333,7 +336,6 @@ namespace std ...@@ -333,7 +336,6 @@ namespace std
string __found_grouping; string __found_grouping;
if (__lc->_M_use_grouping) if (__lc->_M_use_grouping)
__found_grouping.reserve(32); __found_grouping.reserve(32);
int __sep_pos = 0;
const char_type* __q; const char_type* __q;
const char_type* __lit_zero = __lit + __num_base::_S_izero; const char_type* __lit_zero = __lit + __num_base::_S_izero;
while (!__testeof) while (!__testeof)
...@@ -353,7 +355,9 @@ namespace std ...@@ -353,7 +355,9 @@ namespace std
} }
else else
{ {
__err |= ios_base::failbit; // NB: __convert_to_v will not assign __v and will
// set the failbit.
__xtrc.clear();
break; break;
} }
} }
...@@ -383,7 +387,7 @@ namespace std ...@@ -383,7 +387,7 @@ namespace std
} }
else if ((__c == __lit[__num_base::_S_ie] else if ((__c == __lit[__num_base::_S_ie]
|| __c == __lit[__num_base::_S_iE]) || __c == __lit[__num_base::_S_iE])
&& __found_mantissa && !__found_sci) && !__found_sci && __found_mantissa)
{ {
// Scientific notation. // Scientific notation.
if (__found_grouping.size() && !__found_dec) if (__found_grouping.size() && !__found_dec)
...@@ -500,6 +504,7 @@ namespace std ...@@ -500,6 +504,7 @@ namespace std
// Next, look for leading zeros and check required digits // Next, look for leading zeros and check required digits
// for base formats. // for base formats.
bool __found_zero = false; bool __found_zero = false;
int __sep_pos = 0;
while (!__testeof) while (!__testeof)
{ {
if (__lc->_M_use_grouping && __c == __lc->_M_thousands_sep if (__lc->_M_use_grouping && __c == __lc->_M_thousands_sep
...@@ -507,25 +512,27 @@ namespace std ...@@ -507,25 +512,27 @@ namespace std
break; break;
else if (__c == __lit[__num_base::_S_izero] else if (__c == __lit[__num_base::_S_izero]
&& (!__found_zero || __base == 10)) && (!__found_zero || __base == 10))
__found_zero = true;
else if (__found_zero)
{ {
if (__c == __lit[__num_base::_S_ix] __found_zero = true;
|| __c == __lit[__num_base::_S_iX]) ++__sep_pos;
if (__basefield == 0)
__base = 8;
if (__base == 8)
__sep_pos = 0;
}
else if (__found_zero
&& (__c == __lit[__num_base::_S_ix]
|| __c == __lit[__num_base::_S_iX]))
{
if (__basefield == 0)
__base = 16;
if (__base == 16)
{ {
if (__basefield == 0) __found_zero = false;
__base = 16; __sep_pos = 0;
if (__base == 16)
__found_zero = false;
else
break;
} }
else else
{ break;
if (__basefield == 0)
__base = 8;
break;
}
} }
else else
break; break;
...@@ -549,8 +556,7 @@ namespace std ...@@ -549,8 +556,7 @@ namespace std
string __found_grouping; string __found_grouping;
if (__lc->_M_use_grouping) if (__lc->_M_use_grouping)
__found_grouping.reserve(32); __found_grouping.reserve(32);
int __sep_pos = 0; bool __testfail = false;
bool __overflow = false;
const __unsigned_type __max = __negative ? const __unsigned_type __max = __negative ?
-numeric_limits<_ValueT>::min() : numeric_limits<_ValueT>::max(); -numeric_limits<_ValueT>::min() : numeric_limits<_ValueT>::max();
const __unsigned_type __smax = __max / __base; const __unsigned_type __smax = __max / __base;
...@@ -572,7 +578,7 @@ namespace std ...@@ -572,7 +578,7 @@ namespace std
} }
else else
{ {
__err |= ios_base::failbit; __testfail = true;
break; break;
} }
} }
...@@ -584,11 +590,11 @@ namespace std ...@@ -584,11 +590,11 @@ namespace std
if (__digit > 15) if (__digit > 15)
__digit -= 6; __digit -= 6;
if (__result > __smax) if (__result > __smax)
__overflow = true; __testfail = true;
else else
{ {
__result *= __base; __result *= __base;
__overflow |= __result > __max - __digit; __testfail |= __result > __max - __digit;
__result += __digit; __result += __digit;
++__sep_pos; ++__sep_pos;
} }
...@@ -616,8 +622,8 @@ namespace std ...@@ -616,8 +622,8 @@ namespace std
__err |= ios_base::failbit; __err |= ios_base::failbit;
} }
if (!(__err & ios_base::failbit) && !__overflow if (!__testfail && (__sep_pos || __found_zero
&& (__sep_pos || __found_zero || __found_grouping.size())) || __found_grouping.size()))
__v = __negative ? -__result : __result; __v = __negative ? -__result : __result;
else else
__err |= ios_base::failbit; __err |= ios_base::failbit;
...@@ -1444,7 +1450,7 @@ namespace std ...@@ -1444,7 +1450,7 @@ namespace std
if (!std::__verify_grouping(__lc->_M_grouping, if (!std::__verify_grouping(__lc->_M_grouping,
__lc->_M_grouping_size, __lc->_M_grouping_size,
__grouping_tmp)) __grouping_tmp))
__testvalid = false; __err |= ios_base::failbit;
} }
// Iff not enough digits were supplied after the decimal-point. // Iff not enough digits were supplied after the decimal-point.
......
// 2005-06-28 Paolo Carlini <pcarlini@suse.de>
// Copyright (C) 2005 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.6.1.1 money_get members
#include <locale>
#include <sstream>
#include <testsuite_hooks.h>
struct My_money_io : public std::moneypunct<char, false>
{
std::string do_grouping() const { return "\1"; }
char_type do_thousands_sep() const { return '#'; }
pattern do_neg_format() const
{
pattern pat = { { symbol, none, sign, value } };
return pat;
}
};
// libstdc++/22131
void test01()
{
using namespace std;
typedef istreambuf_iterator<char> InIt;
bool test __attribute__((unused)) = true;
locale loc(locale::classic(), new My_money_io);
string buffer1("00#0#1");
string buffer2("000##1");
bool intl = false;
InIt iend1, iend2;
ios_base::iostate err1, err2;
string val1, val2;
const money_get<char,InIt>& mg =
use_facet<money_get<char, InIt> >(loc);
istringstream fmt1(buffer1);
fmt1.imbue(loc);
InIt ibeg1(fmt1);
err1 = ios_base::goodbit;
mg.get(ibeg1, iend1, intl, fmt1, err1, val1);
VERIFY( err1 == (ios_base::eofbit | ios_base::failbit) );
VERIFY( val1 == "1" );
istringstream fmt2(buffer2);
fmt2.imbue(loc);
InIt ibeg2(fmt2);
err2 = ios_base::goodbit;
mg.get(ibeg2, iend2, intl, fmt2, err2, val2);
VERIFY( err2 == ios_base::failbit );
VERIFY( *ibeg2 == '#' );
VERIFY( val2 == "" );
}
int main()
{
test01();
return 0;
}
// 2005-06-28 Paolo Carlini <pcarlini@suse.de>
// Copyright (C) 2005 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.6.1.1 money_get members
#include <locale>
#include <sstream>
#include <testsuite_hooks.h>
struct My_money_io : public std::moneypunct<wchar_t, false>
{
std::string do_grouping() const { return "\1"; }
char_type do_thousands_sep() const { return L'#'; }
pattern do_neg_format() const
{
pattern pat = { { symbol, none, sign, value } };
return pat;
}
};
// libstdc++/22131
void test01()
{
using namespace std;
typedef istreambuf_iterator<wchar_t> InIt;
bool test __attribute__((unused)) = true;
locale loc(locale::classic(), new My_money_io);
wstring buffer1(L"00#0#1");
wstring buffer2(L"000##1");
bool intl = false;
InIt iend1, iend2;
ios_base::iostate err1, err2;
wstring val1, val2;
const money_get<wchar_t,InIt>& mg =
use_facet<money_get<wchar_t, InIt> >(loc);
wistringstream fmt1(buffer1);
fmt1.imbue(loc);
InIt ibeg1(fmt1);
err1 = ios_base::goodbit;
mg.get(ibeg1, iend1, intl, fmt1, err1, val1);
VERIFY( err1 == (ios_base::eofbit | ios_base::failbit) );
VERIFY( val1 == L"1" );
wistringstream fmt2(buffer2);
fmt2.imbue(loc);
InIt ibeg2(fmt2);
err2 = ios_base::goodbit;
mg.get(ibeg2, iend2, intl, fmt2, err2, val2);
VERIFY( err2 == ios_base::failbit );
VERIFY( *ibeg2 == L'#' );
VERIFY( val2 == L"" );
}
int main()
{
test01();
return 0;
}
// 2003-12-22 Paolo Carlini <pcarlini@suse.de> // 2003-12-22 Paolo Carlini <pcarlini@suse.de>
// Copyright (C) 2003 Free Software Foundation // Copyright (C) 2003, 2004, 2005 Free Software Foundation
// //
// This file is part of the GNU ISO C++ Library. This library is free // 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 // software; you can redistribute it and/or modify it under the
...@@ -60,8 +60,9 @@ void test01() ...@@ -60,8 +60,9 @@ void test01()
long l3 = 1l; long l3 = 1l;
long l4 = 63l; long l4 = 63l;
double d = 0.0; double d = 0.0;
double d1 = .4; double d1 = .4;
double d2 = .1; double d2 = 0.0;
double d3 = .1;
iss1.str("+3"); iss1.str("+3");
err = ios_base::goodbit; err = ios_base::goodbit;
...@@ -128,6 +129,7 @@ void test01() ...@@ -128,6 +129,7 @@ void test01()
end = ng2.get(iss2.rdbuf(), 0, iss2, err, l); end = ng2.get(iss2.rdbuf(), 0, iss2, err, l);
VERIFY( err == ios_base::failbit ); VERIFY( err == ios_base::failbit );
VERIFY( *end == 'X' ); VERIFY( *end == 'X' );
VERIFY( l == l3 );
iss2.str("000778"); iss2.str("000778");
iss2.clear(); iss2.clear();
...@@ -141,15 +143,15 @@ void test01() ...@@ -141,15 +143,15 @@ void test01()
iss2.clear(); iss2.clear();
err = ios_base::goodbit; err = ios_base::goodbit;
end = ng2.get(iss2.rdbuf(), 0, iss2, err, d); end = ng2.get(iss2.rdbuf(), 0, iss2, err, d);
VERIFY( err == ios_base::failbit ); VERIFY( err == (ios_base::eofbit | ios_base::failbit) );
VERIFY( *end == 'X' ); VERIFY( d == d2 );
iss2.str("-1"); iss2.str("-1");
iss2.clear(); iss2.clear();
err = ios_base::goodbit; err = ios_base::goodbit;
end = ng2.get(iss2.rdbuf(), 0, iss2, err, d); end = ng2.get(iss2.rdbuf(), 0, iss2, err, d);
VERIFY( err == ios_base::eofbit ); VERIFY( err == ios_base::eofbit );
VERIFY( d == d2 ); VERIFY( d == d3 );
} }
......
// 2005-06-28 Paolo Carlini <pcarlini@suse.de>
// Copyright (C) 2005 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.1.1 num_get members
#include <locale>
#include <sstream>
#include <testsuite_hooks.h>
struct Punct: std::numpunct<char>
{
std::string do_grouping() const { return "\1"; }
char do_thousands_sep() const { return '#'; }
};
// libstdc++/22131
void test01()
{
using namespace std;
typedef istreambuf_iterator<char> iterator_type;
bool test __attribute__((unused)) = true;
istringstream iss1, iss2;
iss1.imbue(locale(iss1.getloc(), new Punct));
const num_get<char>& ng1 = use_facet<num_get<char> >(iss1.getloc());
ios_base::iostate err = ios_base::goodbit;
iterator_type end;
long l = 0l;
long l1 = 1l;
long l2 = 2l;
long l3 = 3l;
double d = 0.0;
double d1 = 1.0;
double d2 = 2.0;
iss1.str("00#0#1");
err = ios_base::goodbit;
end = ng1.get(iss1.rdbuf(), 0, iss1, err, l);
VERIFY( err == (ios_base::eofbit | ios_base::failbit) );
VERIFY( l == l1 );
iss1.str("000##2");
iss1.clear();
err = ios_base::goodbit;
end = ng1.get(iss1.rdbuf(), 0, iss1, err, l);
VERIFY( err == ios_base::failbit );
VERIFY( *end == '#' );
VERIFY( l == l1 );
iss1.str("0#0#0#2");
iss1.clear();
err = ios_base::goodbit;
end = ng1.get(iss1.rdbuf(), 0, iss1, err, l);
VERIFY( err == ios_base::eofbit );
VERIFY( l == l2 );
iss1.str("00#0#1");
iss1.clear();
err = ios_base::goodbit;
end = ng1.get(iss1.rdbuf(), 0, iss1, err, d);
VERIFY( err == (ios_base::eofbit | ios_base::failbit) );
VERIFY( d == d1 );
iss1.str("000##2");
iss1.clear();
err = ios_base::goodbit;
end = ng1.get(iss1.rdbuf(), 0, iss1, err, d);
VERIFY( err == ios_base::failbit );
VERIFY( *end == '#' );
VERIFY( d == d1 );
iss1.str("0#0#0#2");
iss1.clear();
err = ios_base::goodbit;
end = ng1.get(iss1.rdbuf(), 0, iss1, err, d);
VERIFY( err == ios_base::eofbit );
VERIFY( d == d2 );
iss1.str("0#0");
iss1.clear();
iss1.unsetf(ios::basefield);
err = ios_base::goodbit;
end = ng1.get(iss1.rdbuf(), 0, iss1, err, l);
VERIFY( err == ios_base::failbit );
VERIFY( *end == '#' );
VERIFY( l == l2 );
iss1.str("00#0#3");
iss1.clear();
err = ios_base::goodbit;
end = ng1.get(iss1.rdbuf(), 0, iss1, err, l);
VERIFY( err == ios_base::eofbit );
VERIFY( l == l3 );
iss1.str("00#02");
iss1.clear();
err = ios_base::goodbit;
end = ng1.get(iss1.rdbuf(), 0, iss1, err, l);
VERIFY( err == (ios_base::eofbit | ios_base::failbit) );
VERIFY( l == l2 );
}
int main()
{
test01();
return 0;
}
// 2003-12-22 Paolo Carlini <pcarlini@suse.de> // 2003-12-22 Paolo Carlini <pcarlini@suse.de>
// Copyright (C) 2003 Free Software Foundation // Copyright (C) 2003, 2004, 2005 Free Software Foundation
// //
// This file is part of the GNU ISO C++ Library. This library is free // 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 // software; you can redistribute it and/or modify it under the
...@@ -60,8 +60,9 @@ void test01() ...@@ -60,8 +60,9 @@ void test01()
long l3 = 1l; long l3 = 1l;
long l4 = 63l; long l4 = 63l;
double d = 0.0; double d = 0.0;
double d1 = .4; double d1 = .4;
double d2 = .1; double d2 = 0.0;
double d3 = .1;
iss1.str(L"+3"); iss1.str(L"+3");
err = ios_base::goodbit; err = ios_base::goodbit;
...@@ -128,6 +129,7 @@ void test01() ...@@ -128,6 +129,7 @@ void test01()
end = ng2.get(iss2.rdbuf(), 0, iss2, err, l); end = ng2.get(iss2.rdbuf(), 0, iss2, err, l);
VERIFY( err == ios_base::failbit ); VERIFY( err == ios_base::failbit );
VERIFY( *end == L'X' ); VERIFY( *end == L'X' );
VERIFY( l == l3 );
iss2.str(L"000778"); iss2.str(L"000778");
iss2.clear(); iss2.clear();
...@@ -141,18 +143,17 @@ void test01() ...@@ -141,18 +143,17 @@ void test01()
iss2.clear(); iss2.clear();
err = ios_base::goodbit; err = ios_base::goodbit;
end = ng2.get(iss2.rdbuf(), 0, iss2, err, d); end = ng2.get(iss2.rdbuf(), 0, iss2, err, d);
VERIFY( err == ios_base::failbit ); VERIFY( err == (ios_base::eofbit | ios_base::failbit) );
VERIFY( *end == L'X' ); VERIFY( d == d2 );
iss2.str(L"-1"); iss2.str(L"-1");
iss2.clear(); iss2.clear();
err = ios_base::goodbit; err = ios_base::goodbit;
end = ng2.get(iss2.rdbuf(), 0, iss2, err, d); end = ng2.get(iss2.rdbuf(), 0, iss2, err, d);
VERIFY( err == ios_base::eofbit ); VERIFY( err == ios_base::eofbit );
VERIFY( d == d2 ); VERIFY( d == d3 );
} }
int main() int main()
{ {
test01(); test01();
......
// 2005-06-28 Paolo Carlini <pcarlini@suse.de>
// Copyright (C) 2005 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.1.1 num_get members
#include <locale>
#include <sstream>
#include <testsuite_hooks.h>
struct Punct: std::numpunct<wchar_t>
{
std::string do_grouping() const { return "\1"; }
wchar_t do_thousands_sep() const { return L'#'; }
};
// libstdc++/22131
void test01()
{
using namespace std;
typedef istreambuf_iterator<wchar_t> iterator_type;
bool test __attribute__((unused)) = true;
wistringstream iss1, iss2;
iss1.imbue(locale(iss1.getloc(), new Punct));
const num_get<wchar_t>& ng1 = use_facet<num_get<wchar_t> >(iss1.getloc());
ios_base::iostate err = ios_base::goodbit;
iterator_type end;
long l = 0l;
long l1 = 1l;
long l2 = 2l;
long l3 = 3l;
double d = 0.0;
double d1 = 1.0;
double d2 = 2.0;
iss1.str(L"00#0#1");
err = ios_base::goodbit;
end = ng1.get(iss1.rdbuf(), 0, iss1, err, l);
VERIFY( err == (ios_base::eofbit | ios_base::failbit) );
VERIFY( l == l1 );
iss1.str(L"000##2");
iss1.clear();
err = ios_base::goodbit;
end = ng1.get(iss1.rdbuf(), 0, iss1, err, l);
VERIFY( err == ios_base::failbit );
VERIFY( *end == L'#' );
VERIFY( l == l1 );
iss1.str(L"0#0#0#2");
iss1.clear();
err = ios_base::goodbit;
end = ng1.get(iss1.rdbuf(), 0, iss1, err, l);
VERIFY( err == ios_base::eofbit );
VERIFY( l == l2 );
iss1.str(L"00#0#1");
iss1.clear();
err = ios_base::goodbit;
end = ng1.get(iss1.rdbuf(), 0, iss1, err, d);
VERIFY( err == (ios_base::eofbit | ios_base::failbit) );
VERIFY( d == d1 );
iss1.str(L"000##2");
iss1.clear();
err = ios_base::goodbit;
end = ng1.get(iss1.rdbuf(), 0, iss1, err, d);
VERIFY( err == ios_base::failbit );
VERIFY( *end == L'#' );
VERIFY( d == d1 );
iss1.str(L"0#0#0#2");
iss1.clear();
err = ios_base::goodbit;
end = ng1.get(iss1.rdbuf(), 0, iss1, err, d);
VERIFY( err == ios_base::eofbit );
VERIFY( d == d2 );
iss1.str(L"0#0");
iss1.clear();
iss1.unsetf(ios::basefield);
err = ios_base::goodbit;
end = ng1.get(iss1.rdbuf(), 0, iss1, err, l);
VERIFY( err == ios_base::failbit );
VERIFY( *end == L'#' );
VERIFY( l == l2 );
iss1.str(L"00#0#3");
iss1.clear();
err = ios_base::goodbit;
end = ng1.get(iss1.rdbuf(), 0, iss1, err, l);
VERIFY( err == ios_base::eofbit );
VERIFY( l == l3 );
iss1.str(L"00#02");
iss1.clear();
err = ios_base::goodbit;
end = ng1.get(iss1.rdbuf(), 0, iss1, err, l);
VERIFY( err == (ios_base::eofbit | ios_base::failbit) );
VERIFY( l == l2 );
}
int main()
{
test01();
return 0;
}
// 1999-04-12 bkoz // 1999-04-12 bkoz
// Copyright (C) 1999, 2000, 2002, 2003 Free Software Foundation, Inc. // Copyright (C) 1999, 2000, 2002, 2003, 2004, 2005
// Free Software Foundation, Inc.
// //
// This file is part of the GNU ISO C++ Library. This library is free // 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 // software; you can redistribute it and/or modify it under the
...@@ -62,7 +63,7 @@ void test07() ...@@ -62,7 +63,7 @@ void test07()
is.clear(); is.clear();
is >> h2; is >> h2;
VERIFY( h2 == 0 ); VERIFY( h2 == 1232224 );
VERIFY( static_cast<bool>(is.rdstate() & std::ios_base::failbit) ); VERIFY( static_cast<bool>(is.rdstate() & std::ios_base::failbit) );
VERIFY( static_cast<bool>(is.rdstate() & std::ios_base::eofbit) ); VERIFY( static_cast<bool>(is.rdstate() & std::ios_base::eofbit) );
...@@ -124,8 +125,9 @@ void test07() ...@@ -124,8 +125,9 @@ void test07()
VERIFY( is.good() ); VERIFY( is.good() );
is >> h2; is >> h2;
VERIFY( h2 == 0 ); VERIFY( h2 == 1000000 );
VERIFY( static_cast<bool>(is.rdstate() & std::ios_base::failbit) ); VERIFY( static_cast<bool>(is.rdstate() & std::ios_base::failbit) );
h2 = 0;
is.clear(); is.clear();
is >> h2; is >> h2;
...@@ -134,7 +136,7 @@ void test07() ...@@ -134,7 +136,7 @@ void test07()
h2 = 0; h2 = 0;
is >> h2; is >> h2;
VERIFY( h2 == 0 ); VERIFY( h2 == 1234567 );
VERIFY( static_cast<bool>(is.rdstate() & std::ios_base::failbit) ); VERIFY( static_cast<bool>(is.rdstate() & std::ios_base::failbit) );
VERIFY( static_cast<bool>(is.rdstate() & std::ios_base::eofbit) ); VERIFY( static_cast<bool>(is.rdstate() & std::ios_base::eofbit) );
is.clear(); is.clear();
......
// Copyright (C) 2004 Free Software Foundation, Inc. // Copyright (C) 2004, 2005 Free Software Foundation, Inc.
// //
// This file is part of the GNU ISO C++ Library. This library is free // 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 // software; you can redistribute it and/or modify it under the
...@@ -59,8 +59,8 @@ void test07() ...@@ -59,8 +59,8 @@ void test07()
VERIFY( is.good() ); VERIFY( is.good() );
is.clear(); is.clear();
is >> h2; is >> h2;
VERIFY( h2 == 0 ); VERIFY( h2 == 1232224 );
VERIFY( static_cast<bool>(is.rdstate() & std::ios_base::failbit) ); VERIFY( static_cast<bool>(is.rdstate() & std::ios_base::failbit) );
VERIFY( static_cast<bool>(is.rdstate() & std::ios_base::eofbit) ); VERIFY( static_cast<bool>(is.rdstate() & std::ios_base::eofbit) );
...@@ -122,8 +122,9 @@ void test07() ...@@ -122,8 +122,9 @@ void test07()
VERIFY( is.good() ); VERIFY( is.good() );
is >> h2; is >> h2;
VERIFY( h2 == 0 ); VERIFY( h2 == 1000000 );
VERIFY( static_cast<bool>(is.rdstate() & std::ios_base::failbit) ); VERIFY( static_cast<bool>(is.rdstate() & std::ios_base::failbit) );
h2 = 0;
is.clear(); is.clear();
is >> h2; is >> h2;
...@@ -132,7 +133,7 @@ void test07() ...@@ -132,7 +133,7 @@ void test07()
h2 = 0; h2 = 0;
is >> h2; is >> h2;
VERIFY( h2 == 0 ); VERIFY( h2 == 1234567 );
VERIFY( static_cast<bool>(is.rdstate() & std::ios_base::failbit) ); VERIFY( static_cast<bool>(is.rdstate() & std::ios_base::failbit) );
VERIFY( static_cast<bool>(is.rdstate() & std::ios_base::eofbit) ); VERIFY( static_cast<bool>(is.rdstate() & std::ios_base::eofbit) );
is.clear(); is.clear();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment