This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[v3] libstdc++/6750



I realized shortly after I replied to Andreas yesterday what a fool
I'd been. Oh well. This should fix it, it also adds tests.

tested x86/linux

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.

Index: include/bits/ostream.tcc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/bits/ostream.tcc,v
retrieving revision 1.28
diff -c -p -r1.28 ostream.tcc
*** include/bits/ostream.tcc	15 May 2002 14:38:30 -0000	1.28
--- include/bits/ostream.tcc	24 May 2002 15:41:37 -0000
*************** namespace std 
*** 119,137 ****
      basic_ostream<_CharT, _Traits>::operator<<(__streambuf_type* __sbin)
      {
        sentry __cerb(*this);
!       if (__cerb)
  	{
  	  try
  	    {
! 	      streamsize __xtrct = 0;
! 	      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);
  	    }
  	  catch(exception& __fail)
--- 119,129 ----
      basic_ostream<_CharT, _Traits>::operator<<(__streambuf_type* __sbin)
      {
        sentry __cerb(*this);
!       if (__cerb && __sbin)
  	{
  	  try
  	    {
! 	      if (!__copy_streambufs(*this, __sbin, this->rdbuf()))
  		this->setstate(ios_base::failbit);
  	    }
  	  catch(exception& __fail)
*************** namespace std 
*** 143,148 ****
--- 135,142 ----
  		__throw_exception_again;
  	    }
  	}
+       else if (!__sbin)
+ 	this->setstate(ios_base::badbit);
        return *this;
      }
  
*************** namespace std 
*** 539,552 ****
      {
        typedef basic_ostream<_CharT, _Traits> __ostream_type;
        typename __ostream_type::sentry __cerb(__out);
!       if (__cerb)
  	{
  	  try 
  	    {
  	      streamsize __w = __out.width();
  	      _CharT* __pads = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) * __w));
! 	      streamsize __len = __s 
! 		           ? static_cast<streamsize>(_Traits::length(__s)) : 0;
  	      if (__w > __len)
  		{
  		  __pad(__out, __out.fill(), __pads, __s, __w, __len, false);
--- 533,545 ----
      {
        typedef basic_ostream<_CharT, _Traits> __ostream_type;
        typename __ostream_type::sentry __cerb(__out);
!       if (__cerb && __s)
  	{
  	  try 
  	    {
  	      streamsize __w = __out.width();
  	      _CharT* __pads = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) * __w));
! 	      streamsize __len = static_cast<streamsize>(_Traits::length(__s));
  	      if (__w > __len)
  		{
  		  __pad(__out, __out.fill(), __pads, __s, __w, __len, false);
*************** namespace std 
*** 555,562 ****
  		}
  	      __out.write(__s, __len);
  	      __out.width(0);
- 	      if (!__len)
- 		__out.setstate(ios_base::badbit);
  	    }
  	  catch(exception& __fail)
  	    {
--- 548,553 ----
*************** namespace std 
*** 567,572 ****
--- 558,565 ----
  		__throw_exception_again;
  	    }
  	}
+       else if (!__s)
+ 	__out.setstate(ios_base::badbit);
        return __out;
      }
  
*************** namespace std 
*** 581,589 ****
        typedef char_traits<char>		     __traits_type;
  #endif
        typename __ostream_type::sentry __cerb(__out);
!       if (__cerb)
  	{
! 	  size_t __clen = __s ? __traits_type::length(__s) : 0;
  	  _CharT* __ws = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) * (__clen + 1)));
  	  for (size_t  __i = 0; __i < __clen; ++__i)
  	    __ws[__i] = __out.widen(__s[__i]);
--- 574,582 ----
        typedef char_traits<char>		     __traits_type;
  #endif
        typename __ostream_type::sentry __cerb(__out);
!       if (__cerb && __s)
  	{
! 	  size_t __clen = __traits_type::length(__s);
  	  _CharT* __ws = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) * (__clen + 1)));
  	  for (size_t  __i = 0; __i < __clen; ++__i)
  	    __ws[__i] = __out.widen(__s[__i]);
*************** namespace std 
*** 603,610 ****
  		}
  	      __out.write(__str, __len);
  	      __out.width(0);
- 	      if (!__len)
- 		__out.setstate(ios_base::badbit);
  	    }
  	  catch(exception& __fail)
  	    {
--- 596,601 ----
*************** namespace std 
*** 615,620 ****
--- 606,613 ----
  		__throw_exception_again;
  	    }
  	}
+       else if (!__s)
+ 	__out.setstate(ios_base::badbit);
        return __out;
      }
  
*************** namespace std 
*** 625,638 ****
      {
        typedef basic_ostream<char, _Traits> __ostream_type;
        typename __ostream_type::sentry __cerb(__out);
!       if (__cerb)
  	{
  	  try 
  	    {
  	      streamsize __w = __out.width();
  	      char* __pads = static_cast<char*>(__builtin_alloca(__w));
! 	      streamsize __len = __s ? 
! 		             static_cast<streamsize>(_Traits::length(__s)) : 0;
  	      if (__w > __len)
  		{
  		  __pad(__out, __out.fill(), __pads, __s, __w, __len, false);
--- 618,631 ----
      {
        typedef basic_ostream<char, _Traits> __ostream_type;
        typename __ostream_type::sentry __cerb(__out);
!       if (__cerb && __s)
  	{
  	  try 
  	    {
  	      streamsize __w = __out.width();
  	      char* __pads = static_cast<char*>(__builtin_alloca(__w));
! 	      streamsize __len = static_cast<streamsize>(_Traits::length(__s));
! 
  	      if (__w > __len)
  		{
  		  __pad(__out, __out.fill(), __pads, __s, __w, __len, false);
*************** namespace std 
*** 641,648 ****
  		}
  	      __out.write(__s, __len);
  	      __out.width(0);
- 	      if (!__len)
- 		__out.setstate(ios_base::badbit);
  	    }
  	  catch(exception& __fail)
  	    {
--- 634,639 ----
*************** namespace std 
*** 653,658 ****
--- 644,651 ----
  		__throw_exception_again;
  	    }
  	}
+       else if (!__s)
+ 	__out.setstate(ios_base::badbit);
        return __out;
      }
  
Index: testsuite/27_io/ostream_inserter_char.cc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/testsuite/27_io/ostream_inserter_char.cc,v
retrieving revision 1.9
diff -c -p -r1.9 ostream_inserter_char.cc
*** testsuite/27_io/ostream_inserter_char.cc	15 May 2002 14:38:30 -0000	1.9
--- testsuite/27_io/ostream_inserter_char.cc	24 May 2002 15:41:37 -0000
*************** void test08()
*** 296,318 ****
  
    // 1
    std::ostringstream oss;
!   oss << pt << std::endl;
    VERIFY( oss.bad() );
    VERIFY( oss.str().size() == 0 );
  
  #if _GLIBCPP_USE_WCHAR_T
    // 2
    std::wostringstream woss;
!   woss << pt << std::endl;
    VERIFY( woss.bad() );
    VERIFY( woss.str().size() == 0 );
  
    // 3
    wchar_t* wt = NULL;
    woss.clear();
!   woss << wt << std::endl;
    VERIFY( woss.bad() );
    VERIFY( woss.str().size() == 0 );
  #endif
  }
  
--- 296,330 ----
  
    // 1
    std::ostringstream oss;
!   oss << pt;
    VERIFY( oss.bad() );
    VERIFY( oss.str().size() == 0 );
  
+   oss.clear();
+   oss << "";
+   VERIFY( oss.good() );
+ 
  #if _GLIBCPP_USE_WCHAR_T
    // 2
    std::wostringstream woss;
!   woss << pt;
    VERIFY( woss.bad() );
    VERIFY( woss.str().size() == 0 );
  
+   woss.clear();
+   woss << "";
+   VERIFY( woss.good() );
+ 
    // 3
    wchar_t* wt = NULL;
    woss.clear();
!   woss << wt;
    VERIFY( woss.bad() );
    VERIFY( woss.str().size() == 0 );
+ 
+   woss.clear();
+   woss << L"";
+   VERIFY( woss.good() );
  #endif
  }
  
Index: testsuite/27_io/ostream_inserter_other.cc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/testsuite/27_io/ostream_inserter_other.cc,v
retrieving revision 1.10
diff -c -p -r1.10 ostream_inserter_other.cc
*** testsuite/27_io/ostream_inserter_other.cc	23 Jan 2002 01:12:10 -0000	1.10
--- testsuite/27_io/ostream_inserter_other.cc	24 May 2002 15:41:37 -0000
***************
*** 1,7 ****
  // 1999-08-16 bkoz
  // 1999-11-01 bkoz
  
! // Copyright (C) 1999, 2000, 2001 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
--- 1,7 ----
  // 1999-08-16 bkoz
  // 1999-11-01 bkoz
  
! // Copyright (C) 1999, 2000, 2001, 2002 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
*************** test02() 
*** 67,73 ****
    f_out1 << strbuf01;
    state02 = f_out1.rdstate();
    VERIFY( state01 != state02 );
!   VERIFY( (state02 & std::ios_base::failbit) != 0 );
  
    // filebuf->filebuf
    std::ifstream f_in(name_01);
--- 67,73 ----
    f_out1 << strbuf01;
    state02 = f_out1.rdstate();
    VERIFY( state01 != state02 );
!   VERIFY( (state02 & std::ios_base::badbit) != 0 );
  
    // filebuf->filebuf
    std::ifstream f_in(name_01);


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]