re PR libstdc++/6750 (ofstream incorrectly sets failbit (severe regression))
2002-05-24 Benjamin Kosnik <bkoz@redhat.com> PR libstdc++/6750 * include/bits/ostream.tcc (ostream::operator<<(const char*)): Fix for empty string literal. (ostream::operator<<(const _CharT*)): Same. (ostream<char>::operator<<(const char*)): Same. (ostream<char>::operator<<(streambuf*)): Same. * testsuite/27_io/ostream_inserter_char.cc (test08): Add tests. * testsuite/27_io/ostream_inserter_other.cc (test02): Modify. From-SVN: r53839
This commit is contained in:
parent
d2f108e266
commit
52f02d949e
3 changed files with 34 additions and 29 deletions
|
@ -119,19 +119,11 @@ namespace std
|
||||||
basic_ostream<_CharT, _Traits>::operator<<(__streambuf_type* __sbin)
|
basic_ostream<_CharT, _Traits>::operator<<(__streambuf_type* __sbin)
|
||||||
{
|
{
|
||||||
sentry __cerb(*this);
|
sentry __cerb(*this);
|
||||||
if (__cerb)
|
if (__cerb && __sbin)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
streamsize __xtrct = 0;
|
if (!__copy_streambufs(*this, __sbin, this->rdbuf()))
|
||||||
if (__sbin)
|
|
||||||
{
|
|
||||||
__streambuf_type* __sbout = this->rdbuf();
|
|
||||||
__xtrct = __copy_streambufs(*this, __sbin, __sbout);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
this->setstate(ios_base::badbit);
|
|
||||||
if (!__xtrct)
|
|
||||||
this->setstate(ios_base::failbit);
|
this->setstate(ios_base::failbit);
|
||||||
}
|
}
|
||||||
catch(exception& __fail)
|
catch(exception& __fail)
|
||||||
|
@ -143,6 +135,8 @@ namespace std
|
||||||
__throw_exception_again;
|
__throw_exception_again;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (!__sbin)
|
||||||
|
this->setstate(ios_base::badbit);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -539,14 +533,13 @@ namespace std
|
||||||
{
|
{
|
||||||
typedef basic_ostream<_CharT, _Traits> __ostream_type;
|
typedef basic_ostream<_CharT, _Traits> __ostream_type;
|
||||||
typename __ostream_type::sentry __cerb(__out);
|
typename __ostream_type::sentry __cerb(__out);
|
||||||
if (__cerb)
|
if (__cerb && __s)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
streamsize __w = __out.width();
|
streamsize __w = __out.width();
|
||||||
_CharT* __pads = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) * __w));
|
_CharT* __pads = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) * __w));
|
||||||
streamsize __len = __s
|
streamsize __len = static_cast<streamsize>(_Traits::length(__s));
|
||||||
? static_cast<streamsize>(_Traits::length(__s)) : 0;
|
|
||||||
if (__w > __len)
|
if (__w > __len)
|
||||||
{
|
{
|
||||||
__pad(__out, __out.fill(), __pads, __s, __w, __len, false);
|
__pad(__out, __out.fill(), __pads, __s, __w, __len, false);
|
||||||
|
@ -555,8 +548,6 @@ namespace std
|
||||||
}
|
}
|
||||||
__out.write(__s, __len);
|
__out.write(__s, __len);
|
||||||
__out.width(0);
|
__out.width(0);
|
||||||
if (!__len)
|
|
||||||
__out.setstate(ios_base::badbit);
|
|
||||||
}
|
}
|
||||||
catch(exception& __fail)
|
catch(exception& __fail)
|
||||||
{
|
{
|
||||||
|
@ -567,6 +558,8 @@ namespace std
|
||||||
__throw_exception_again;
|
__throw_exception_again;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (!__s)
|
||||||
|
__out.setstate(ios_base::badbit);
|
||||||
return __out;
|
return __out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -581,9 +574,9 @@ namespace std
|
||||||
typedef char_traits<char> __traits_type;
|
typedef char_traits<char> __traits_type;
|
||||||
#endif
|
#endif
|
||||||
typename __ostream_type::sentry __cerb(__out);
|
typename __ostream_type::sentry __cerb(__out);
|
||||||
if (__cerb)
|
if (__cerb && __s)
|
||||||
{
|
{
|
||||||
size_t __clen = __s ? __traits_type::length(__s) : 0;
|
size_t __clen = __traits_type::length(__s);
|
||||||
_CharT* __ws = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) * (__clen + 1)));
|
_CharT* __ws = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) * (__clen + 1)));
|
||||||
for (size_t __i = 0; __i < __clen; ++__i)
|
for (size_t __i = 0; __i < __clen; ++__i)
|
||||||
__ws[__i] = __out.widen(__s[__i]);
|
__ws[__i] = __out.widen(__s[__i]);
|
||||||
|
@ -603,8 +596,6 @@ namespace std
|
||||||
}
|
}
|
||||||
__out.write(__str, __len);
|
__out.write(__str, __len);
|
||||||
__out.width(0);
|
__out.width(0);
|
||||||
if (!__len)
|
|
||||||
__out.setstate(ios_base::badbit);
|
|
||||||
}
|
}
|
||||||
catch(exception& __fail)
|
catch(exception& __fail)
|
||||||
{
|
{
|
||||||
|
@ -615,6 +606,8 @@ namespace std
|
||||||
__throw_exception_again;
|
__throw_exception_again;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (!__s)
|
||||||
|
__out.setstate(ios_base::badbit);
|
||||||
return __out;
|
return __out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -625,14 +618,14 @@ namespace std
|
||||||
{
|
{
|
||||||
typedef basic_ostream<char, _Traits> __ostream_type;
|
typedef basic_ostream<char, _Traits> __ostream_type;
|
||||||
typename __ostream_type::sentry __cerb(__out);
|
typename __ostream_type::sentry __cerb(__out);
|
||||||
if (__cerb)
|
if (__cerb && __s)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
streamsize __w = __out.width();
|
streamsize __w = __out.width();
|
||||||
char* __pads = static_cast<char*>(__builtin_alloca(__w));
|
char* __pads = static_cast<char*>(__builtin_alloca(__w));
|
||||||
streamsize __len = __s ?
|
streamsize __len = static_cast<streamsize>(_Traits::length(__s));
|
||||||
static_cast<streamsize>(_Traits::length(__s)) : 0;
|
|
||||||
if (__w > __len)
|
if (__w > __len)
|
||||||
{
|
{
|
||||||
__pad(__out, __out.fill(), __pads, __s, __w, __len, false);
|
__pad(__out, __out.fill(), __pads, __s, __w, __len, false);
|
||||||
|
@ -641,8 +634,6 @@ namespace std
|
||||||
}
|
}
|
||||||
__out.write(__s, __len);
|
__out.write(__s, __len);
|
||||||
__out.width(0);
|
__out.width(0);
|
||||||
if (!__len)
|
|
||||||
__out.setstate(ios_base::badbit);
|
|
||||||
}
|
}
|
||||||
catch(exception& __fail)
|
catch(exception& __fail)
|
||||||
{
|
{
|
||||||
|
@ -653,6 +644,8 @@ namespace std
|
||||||
__throw_exception_again;
|
__throw_exception_again;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (!__s)
|
||||||
|
__out.setstate(ios_base::badbit);
|
||||||
return __out;
|
return __out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -296,23 +296,35 @@ void test08()
|
||||||
|
|
||||||
// 1
|
// 1
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
oss << pt << std::endl;
|
oss << pt;
|
||||||
VERIFY( oss.bad() );
|
VERIFY( oss.bad() );
|
||||||
VERIFY( oss.str().size() == 0 );
|
VERIFY( oss.str().size() == 0 );
|
||||||
|
|
||||||
|
oss.clear();
|
||||||
|
oss << "";
|
||||||
|
VERIFY( oss.good() );
|
||||||
|
|
||||||
#if _GLIBCPP_USE_WCHAR_T
|
#if _GLIBCPP_USE_WCHAR_T
|
||||||
// 2
|
// 2
|
||||||
std::wostringstream woss;
|
std::wostringstream woss;
|
||||||
woss << pt << std::endl;
|
woss << pt;
|
||||||
VERIFY( woss.bad() );
|
VERIFY( woss.bad() );
|
||||||
VERIFY( woss.str().size() == 0 );
|
VERIFY( woss.str().size() == 0 );
|
||||||
|
|
||||||
|
woss.clear();
|
||||||
|
woss << "";
|
||||||
|
VERIFY( woss.good() );
|
||||||
|
|
||||||
// 3
|
// 3
|
||||||
wchar_t* wt = NULL;
|
wchar_t* wt = NULL;
|
||||||
woss.clear();
|
woss.clear();
|
||||||
woss << wt << std::endl;
|
woss << wt;
|
||||||
VERIFY( woss.bad() );
|
VERIFY( woss.bad() );
|
||||||
VERIFY( woss.str().size() == 0 );
|
VERIFY( woss.str().size() == 0 );
|
||||||
|
|
||||||
|
woss.clear();
|
||||||
|
woss << L"";
|
||||||
|
VERIFY( woss.good() );
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
// 1999-08-16 bkoz
|
// 1999-08-16 bkoz
|
||||||
// 1999-11-01 bkoz
|
// 1999-11-01 bkoz
|
||||||
|
|
||||||
// Copyright (C) 1999, 2000, 2001 Free Software Foundation
|
// Copyright (C) 1999, 2000, 2001, 2002 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
|
||||||
|
@ -67,7 +67,7 @@ test02()
|
||||||
f_out1 << strbuf01;
|
f_out1 << strbuf01;
|
||||||
state02 = f_out1.rdstate();
|
state02 = f_out1.rdstate();
|
||||||
VERIFY( state01 != state02 );
|
VERIFY( state01 != state02 );
|
||||||
VERIFY( (state02 & std::ios_base::failbit) != 0 );
|
VERIFY( (state02 & std::ios_base::badbit) != 0 );
|
||||||
|
|
||||||
// filebuf->filebuf
|
// filebuf->filebuf
|
||||||
std::ifstream f_in(name_01);
|
std::ifstream f_in(name_01);
|
||||||
|
|
Loading…
Add table
Reference in a new issue