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
This commit is contained in:
Paolo Carlini 2005-06-29 11:48:53 +00:00 committed by Paolo Carlini
parent 43b3a5b10f
commit d04e9b7fef
12 changed files with 577 additions and 142 deletions

View File

@ -1,3 +1,25 @@
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>
* acinclude.m4 (GLIBCXX_ENABLE_SJLJ_EXCEPTIONS): Check for

View File

@ -1,6 +1,7 @@
// 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
// software; you can redistribute it and/or modify it under the
@ -50,39 +51,36 @@ namespace std
__convert_to_v(const char* __s, float& __v, ios_base::iostate& __err,
const __c_locale&)
{
if (!(__err & ios_base::failbit))
{
// Assumes __s formatted for "C" locale.
char* __old = strdup(setlocale(LC_ALL, NULL));
setlocale(LC_ALL, "C");
char* __sanity;
errno = 0;
// Assumes __s formatted for "C" locale.
errno = 0;
char* __old = strdup(setlocale(LC_ALL, NULL));
setlocale(LC_ALL, "C");
char* __sanity;
#if defined(_GLIBCXX_HAVE_STRTOF)
float __f = strtof(__s, &__sanity);
float __f = strtof(__s, &__sanity);
#else
double __d = strtod(__s, &__sanity);
float __f = static_cast<float>(__d);
double __d = strtod(__s, &__sanity);
float __f = static_cast<float>(__d);
#ifdef _GLIBCXX_HAVE_FINITEF
if (!finitef (__f))
errno = ERANGE;
if (!finitef (__f))
errno = ERANGE;
#elif defined (_GLIBCXX_HAVE_FINITE)
if (!finite (static_cast<double> (__f)))
errno = ERANGE;
if (!finite (static_cast<double> (__f)))
errno = ERANGE;
#elif defined (_GLIBCXX_HAVE_ISINF)
if (isinf (static_cast<double> (__f)))
errno = ERANGE;
if (isinf (static_cast<double> (__f)))
errno = ERANGE;
#else
if (fabs(__d) > numeric_limits<float>::max())
errno = ERANGE;
if (fabs(__d) > numeric_limits<float>::max())
errno = ERANGE;
#endif
#endif
if (__sanity != __s && errno != ERANGE)
__v = __f;
else
__err |= ios_base::failbit;
setlocale(LC_ALL, __old);
free(__old);
}
if (__sanity != __s && errno != ERANGE)
__v = __f;
else
__err |= ios_base::failbit;
setlocale(LC_ALL, __old);
free(__old);
}
template<>
@ -90,21 +88,18 @@ namespace std
__convert_to_v(const char* __s, double& __v, ios_base::iostate& __err,
const __c_locale&)
{
if (!(__err & ios_base::failbit))
{
// Assumes __s formatted for "C" locale.
char* __old = strdup(setlocale(LC_ALL, NULL));
setlocale(LC_ALL, "C");
char* __sanity;
errno = 0;
double __d = strtod(__s, &__sanity);
if (__sanity != __s && errno != ERANGE)
__v = __d;
else
__err |= ios_base::failbit;
setlocale(LC_ALL, __old);
free(__old);
}
// Assumes __s formatted for "C" locale.
errno = 0;
char* __old = strdup(setlocale(LC_ALL, NULL));
setlocale(LC_ALL, "C");
char* __sanity;
double __d = strtod(__s, &__sanity);
if (__sanity != __s && errno != ERANGE)
__v = __d;
else
__err |= ios_base::failbit;
setlocale(LC_ALL, __old);
free(__old);
}
template<>
@ -112,31 +107,27 @@ namespace std
__convert_to_v(const char* __s, long double& __v,
ios_base::iostate& __err, const __c_locale&)
{
if (!(__err & ios_base::failbit))
{
// Assumes __s formatted for "C" locale.
char* __old = strdup(setlocale(LC_ALL, NULL));
setlocale(LC_ALL, "C");
// Assumes __s formatted for "C" locale.
errno = 0;
char* __old = strdup(setlocale(LC_ALL, NULL));
setlocale(LC_ALL, "C");
#if defined(_GLIBCXX_HAVE_STRTOLD)
char* __sanity;
errno = 0;
long double __ld = strtold(__s, &__sanity);
if (__sanity != __s && errno != ERANGE)
__v = __ld;
char* __sanity;
long double __ld = strtold(__s, &__sanity);
if (__sanity != __s && errno != ERANGE)
__v = __ld;
#else
typedef char_traits<char>::int_type int_type;
long double __ld;
errno = 0;
int __p = sscanf(__s, "%Lf", &__ld);
if (__p && static_cast<int_type>(__p) != char_traits<char>::eof()
&& errno != ERANGE)
__v = __ld;
typedef char_traits<char>::int_type int_type;
long double __ld;
int __p = sscanf(__s, "%Lf", &__ld);
if (__p && static_cast<int_type>(__p) != char_traits<char>::eof()
&& errno != ERANGE)
__v = __ld;
#endif
else
__err |= ios_base::failbit;
setlocale(LC_ALL, __old);
free(__old);
}
else
__err |= ios_base::failbit;
setlocale(LC_ALL, __old);
free(__old);
}
void

View File

@ -1,6 +1,7 @@
// 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
// software; you can redistribute it and/or modify it under the
@ -46,16 +47,13 @@ namespace std
__convert_to_v(const char* __s, float& __v, ios_base::iostate& __err,
const __c_locale& __cloc)
{
if (!(__err & ios_base::failbit))
{
char* __sanity;
errno = 0;
float __f = __strtof_l(__s, &__sanity, __cloc);
if (__sanity != __s && errno != ERANGE)
__v = __f;
else
__err |= ios_base::failbit;
}
char* __sanity;
errno = 0;
float __f = __strtof_l(__s, &__sanity, __cloc);
if (__sanity != __s && errno != ERANGE)
__v = __f;
else
__err |= ios_base::failbit;
}
template<>
@ -63,16 +61,13 @@ namespace std
__convert_to_v(const char* __s, double& __v, ios_base::iostate& __err,
const __c_locale& __cloc)
{
if (!(__err & ios_base::failbit))
{
char* __sanity;
errno = 0;
double __d = __strtod_l(__s, &__sanity, __cloc);
if (__sanity != __s && errno != ERANGE)
__v = __d;
else
__err |= ios_base::failbit;
}
char* __sanity;
errno = 0;
double __d = __strtod_l(__s, &__sanity, __cloc);
if (__sanity != __s && errno != ERANGE)
__v = __d;
else
__err |= ios_base::failbit;
}
template<>
@ -80,16 +75,13 @@ namespace std
__convert_to_v(const char* __s, long double& __v, ios_base::iostate& __err,
const __c_locale& __cloc)
{
if (!(__err & ios_base::failbit))
{
char* __sanity;
errno = 0;
long double __ld = __strtold_l(__s, &__sanity, __cloc);
if (__sanity != __s && errno != ERANGE)
__v = __ld;
else
__err |= ios_base::failbit;
}
char* __sanity;
errno = 0;
long double __ld = __strtold_l(__s, &__sanity, __cloc);
if (__sanity != __s && errno != ERANGE)
__v = __ld;
else
__err |= ios_base::failbit;
}
void

View File

@ -306,6 +306,7 @@ namespace std
// Next, look for leading zeros.
bool __found_mantissa = false;
int __sep_pos = 0;
while (!__testeof)
{
if (__lc->_M_use_grouping && __c == __lc->_M_thousands_sep
@ -318,6 +319,8 @@ namespace std
__xtrc += '0';
__found_mantissa = true;
}
++__sep_pos;
if (++__beg != __end)
__c = *__beg;
else
@ -333,7 +336,6 @@ namespace std
string __found_grouping;
if (__lc->_M_use_grouping)
__found_grouping.reserve(32);
int __sep_pos = 0;
const char_type* __q;
const char_type* __lit_zero = __lit + __num_base::_S_izero;
while (!__testeof)
@ -353,7 +355,9 @@ namespace std
}
else
{
__err |= ios_base::failbit;
// NB: __convert_to_v will not assign __v and will
// set the failbit.
__xtrc.clear();
break;
}
}
@ -383,7 +387,7 @@ namespace std
}
else if ((__c == __lit[__num_base::_S_ie]
|| __c == __lit[__num_base::_S_iE])
&& __found_mantissa && !__found_sci)
&& !__found_sci && __found_mantissa)
{
// Scientific notation.
if (__found_grouping.size() && !__found_dec)
@ -500,6 +504,7 @@ namespace std
// Next, look for leading zeros and check required digits
// for base formats.
bool __found_zero = false;
int __sep_pos = 0;
while (!__testeof)
{
if (__lc->_M_use_grouping && __c == __lc->_M_thousands_sep
@ -507,25 +512,27 @@ namespace std
break;
else if (__c == __lit[__num_base::_S_izero]
&& (!__found_zero || __base == 10))
__found_zero = true;
else if (__found_zero)
{
if (__c == __lit[__num_base::_S_ix]
|| __c == __lit[__num_base::_S_iX])
__found_zero = true;
++__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)
__base = 16;
if (__base == 16)
__found_zero = false;
else
break;
__found_zero = false;
__sep_pos = 0;
}
else
{
if (__basefield == 0)
__base = 8;
break;
}
break;
}
else
break;
@ -549,8 +556,7 @@ namespace std
string __found_grouping;
if (__lc->_M_use_grouping)
__found_grouping.reserve(32);
int __sep_pos = 0;
bool __overflow = false;
bool __testfail = false;
const __unsigned_type __max = __negative ?
-numeric_limits<_ValueT>::min() : numeric_limits<_ValueT>::max();
const __unsigned_type __smax = __max / __base;
@ -572,7 +578,7 @@ namespace std
}
else
{
__err |= ios_base::failbit;
__testfail = true;
break;
}
}
@ -584,11 +590,11 @@ namespace std
if (__digit > 15)
__digit -= 6;
if (__result > __smax)
__overflow = true;
__testfail = true;
else
{
__result *= __base;
__overflow |= __result > __max - __digit;
__testfail |= __result > __max - __digit;
__result += __digit;
++__sep_pos;
}
@ -616,8 +622,8 @@ namespace std
__err |= ios_base::failbit;
}
if (!(__err & ios_base::failbit) && !__overflow
&& (__sep_pos || __found_zero || __found_grouping.size()))
if (!__testfail && (__sep_pos || __found_zero
|| __found_grouping.size()))
__v = __negative ? -__result : __result;
else
__err |= ios_base::failbit;
@ -1444,7 +1450,7 @@ namespace std
if (!std::__verify_grouping(__lc->_M_grouping,
__lc->_M_grouping_size,
__grouping_tmp))
__testvalid = false;
__err |= ios_base::failbit;
}
// Iff not enough digits were supplied after the decimal-point.

View File

@ -0,0 +1,83 @@
// 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;
}

View File

@ -0,0 +1,83 @@
// 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;
}

View File

@ -1,6 +1,6 @@
// 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
// software; you can redistribute it and/or modify it under the
@ -60,8 +60,9 @@ void test01()
long l3 = 1l;
long l4 = 63l;
double d = 0.0;
double d1 = .4;
double d2 = .1;
double d1 = .4;
double d2 = 0.0;
double d3 = .1;
iss1.str("+3");
err = ios_base::goodbit;
@ -128,6 +129,7 @@ void test01()
end = ng2.get(iss2.rdbuf(), 0, iss2, err, l);
VERIFY( err == ios_base::failbit );
VERIFY( *end == 'X' );
VERIFY( l == l3 );
iss2.str("000778");
iss2.clear();
@ -141,15 +143,15 @@ void test01()
iss2.clear();
err = ios_base::goodbit;
end = ng2.get(iss2.rdbuf(), 0, iss2, err, d);
VERIFY( err == ios_base::failbit );
VERIFY( *end == 'X' );
VERIFY( err == (ios_base::eofbit | ios_base::failbit) );
VERIFY( d == d2 );
iss2.str("-1");
iss2.clear();
err = ios_base::goodbit;
end = ng2.get(iss2.rdbuf(), 0, iss2, err, d);
VERIFY( err == ios_base::eofbit );
VERIFY( d == d2 );
VERIFY( d == d3 );
}

View File

@ -0,0 +1,126 @@
// 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;
}

View File

@ -1,6 +1,6 @@
// 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
// software; you can redistribute it and/or modify it under the
@ -60,8 +60,9 @@ void test01()
long l3 = 1l;
long l4 = 63l;
double d = 0.0;
double d1 = .4;
double d2 = .1;
double d1 = .4;
double d2 = 0.0;
double d3 = .1;
iss1.str(L"+3");
err = ios_base::goodbit;
@ -128,6 +129,7 @@ void test01()
end = ng2.get(iss2.rdbuf(), 0, iss2, err, l);
VERIFY( err == ios_base::failbit );
VERIFY( *end == L'X' );
VERIFY( l == l3 );
iss2.str(L"000778");
iss2.clear();
@ -141,18 +143,17 @@ void test01()
iss2.clear();
err = ios_base::goodbit;
end = ng2.get(iss2.rdbuf(), 0, iss2, err, d);
VERIFY( err == ios_base::failbit );
VERIFY( *end == L'X' );
VERIFY( err == (ios_base::eofbit | ios_base::failbit) );
VERIFY( d == d2 );
iss2.str(L"-1");
iss2.clear();
err = ios_base::goodbit;
end = ng2.get(iss2.rdbuf(), 0, iss2, err, d);
VERIFY( err == ios_base::eofbit );
VERIFY( d == d2 );
VERIFY( d == d3 );
}
int main()
{
test01();

View File

@ -0,0 +1,126 @@
// 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;
}

View File

@ -1,6 +1,7 @@
// 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
// software; you can redistribute it and/or modify it under the
@ -62,7 +63,7 @@ void test07()
is.clear();
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::eofbit) );
@ -124,8 +125,9 @@ void test07()
VERIFY( is.good() );
is >> h2;
VERIFY( h2 == 0 );
VERIFY( h2 == 1000000 );
VERIFY( static_cast<bool>(is.rdstate() & std::ios_base::failbit) );
h2 = 0;
is.clear();
is >> h2;
@ -134,7 +136,7 @@ void test07()
h2 = 0;
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::eofbit) );
is.clear();

View File

@ -1,4 +1,4 @@
// 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
// software; you can redistribute it and/or modify it under the
@ -59,8 +59,8 @@ void test07()
VERIFY( is.good() );
is.clear();
is >> h2;
VERIFY( h2 == 0 );
is >> h2;
VERIFY( h2 == 1232224 );
VERIFY( static_cast<bool>(is.rdstate() & std::ios_base::failbit) );
VERIFY( static_cast<bool>(is.rdstate() & std::ios_base::eofbit) );
@ -122,8 +122,9 @@ void test07()
VERIFY( is.good() );
is >> h2;
VERIFY( h2 == 0 );
VERIFY( h2 == 1000000 );
VERIFY( static_cast<bool>(is.rdstate() & std::ios_base::failbit) );
h2 = 0;
is.clear();
is >> h2;
@ -132,7 +133,7 @@ void test07()
h2 = 0;
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::eofbit) );
is.clear();