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]

Re: [PATCH] 4.0 fix for libstdc++/23871


On Wed, Sep 14, 2005 at 03:37:19PM -0700, Janis Johnson wrote:
> On Thu, Sep 15, 2005 at 12:23:15AM +0200, Paolo Carlini wrote:
> > Hi Janis,
> > 
> > >Sorry, I was running the tests by hand outside of the testsuite and
> > >_GLIBCXX_ASSERT was not set.  With that set, the tests fail for 4.0 with
> > >and without my patch, so apparently the tests require parts of the patch
> > >that I did not backport; my patch has only the changes to std_ostream.h,
> > >which are needed to allow the PR's test case to compile.
> > >  
> > >
> > I see, thanks.
> > 
> > The problem is that the very same flaw (& instead of ==, basically) was
> > present also in ostream.tcc, in two places, for operator<<(long __n) and
> > operator<<(long long __n).
> > 
> > For 4.0 I would rather prefer adjusting only that (in addition to the
> > std_ostream.h hunk), and not touching also the locale classes. Are you
> > willing to test that complete change?
> 
> Sure, I'll do that.

The original 4.0 patch, with only the changes to std_ostream.h, had
no regressions when bootstrapped on powerpc64-linux and regression
tested with -m32/-m64.  It allowed the testcase from 23871 to compile,
but failed the inserters_arithmetic/*char*/7.cc tests that Paolo asked
me to add.

With backports of the std_ostream.h and ostream.tcc changes there were
regressions with

  27_io/basic_ostream/inserters_arithmetic/char/3.cc
  27_io/basic_ostream/inserters_arithmetic/wchar_t/3.cc

This patch, which has been bootstrapped on powerpc64-unknown-linux-gnu
and regression tested with -m32/-m64, has no regressions and passes
the PR test plus the inserters_arithmetic/*char*/7.cc tests.  The change
to ostream.tcc merely prevents it from using || on integers, which is
probably what you meant in your previous mail.

OK for the 4.0-branch after it opens?

2005-09-16  Janis Johnson  <janis187@us.ibm.com>

	PR libstdc++/23871

	Backport:
	2005-07-11  Paolo Carlini  <pcarlini@suse.de>
	* include/std/std_ostream.h (operator<<(short), operator<<(int)):
	Adjust logic, as per the letter of the resolution of DR117 [WP].
	* testsuite/27_io/basic_ostream/inserters_arithmetic/char/7.cc: New.
	* testsuite/27_io/basic_ostream/inserters_arithmetic/wchar_t/7.cc: New.
	
	* include/bits/ostream.tcc (operator<<(long), operator<<(long long)):
	Avoid using || with integers.
	* testsuite/27_io/basic_ostream/inserters_arithmetic/char/23871.cc:
	New.

Index: libstdc++-v3/include/bits/ostream.tcc
===================================================================
RCS file: /opt/gcc-cvs/gcc/libstdc++-v3/include/bits/ostream.tcc,v
retrieving revision 1.54
diff -u -p -r1.54 ostream.tcc
--- libstdc++-v3/include/bits/ostream.tcc	24 Nov 2004 04:11:10 -0000	1.54
+++ libstdc++-v3/include/bits/ostream.tcc	15 Sep 2005 22:33:55 -0000
@@ -135,7 +135,7 @@ namespace std
 	      const ios_base::fmtflags __fmt = (this->flags()
 						& ios_base::basefield);
 	      const __num_put_type& __np = __check_facet(this->_M_num_put);
-	      if ((__fmt & ios_base::oct) || (__fmt & ios_base::hex))
+	      if ((__fmt == ios_base::oct) || (__fmt == ios_base::hex))
 		{
 		  const unsigned long __l = static_cast<unsigned long>(__n);
 		  __b = __np.put(*this, *this, __c, __l).failed();
@@ -193,7 +193,7 @@ namespace std
 	      const ios_base::fmtflags __fmt = (this->flags()
 						& ios_base::basefield);
 	      const __num_put_type& __np = __check_facet(this->_M_num_put);
-	      if ((__fmt & ios_base::oct) || (__fmt & ios_base::hex))
+	      if ((__fmt == ios_base::oct) || (__fmt == ios_base::hex))
 		{
 		  const unsigned long long __l = (static_cast<
 						  unsigned long long>(__n));
Index: libstdc++-v3/include/std/std_ostream.h
===================================================================
RCS file: /opt/gcc-cvs/gcc/libstdc++-v3/include/std/std_ostream.h,v
retrieving revision 1.16
diff -u -p -r1.16 std_ostream.h
--- libstdc++-v3/include/std/std_ostream.h	24 Nov 2004 04:11:21 -0000	1.16
+++ libstdc++-v3/include/std/std_ostream.h	14 Sep 2005 00:08:27 -0000
@@ -175,9 +175,9 @@ namespace std
       __ostream_type& 
       operator<<(short __n)
       { 
-	ios_base::fmtflags __fmt = this->flags() & ios_base::basefield;
-	if (__fmt & ios_base::oct || __fmt & ios_base::hex)
-	  return this->operator<<(static_cast<unsigned long>
+	const ios_base::fmtflags __fmt = this->flags() & ios_base::basefield;
+	if (__fmt == ios_base::oct || __fmt == ios_base::hex)
+	  return this->operator<<(static_cast<long>
 				  (static_cast<unsigned short>(__n)));
 	else
 	  return this->operator<<(static_cast<long>(__n));
@@ -190,9 +190,9 @@ namespace std
       __ostream_type& 
       operator<<(int __n)
       { 
-	ios_base::fmtflags __fmt = this->flags() & ios_base::basefield;
-	if (__fmt & ios_base::oct || __fmt & ios_base::hex)
-	  return this->operator<<(static_cast<unsigned long>
+	const ios_base::fmtflags __fmt = this->flags() & ios_base::basefield;
+	if (__fmt == ios_base::oct || __fmt == ios_base::hex)
+	  return this->operator<<(static_cast<long>
 				  (static_cast<unsigned int>(__n)));
 	else
 	  return this->operator<<(static_cast<long>(__n));
--- /dev/null	2004-06-24 11:06:20.000000000 -0700
+++ libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/23871.cc	2005-09-14 16:16:41.000000000 -0700
@@ -0,0 +1,38 @@
+// 2005-09-15  Janis Johnson  <janis187@us.ibm.com>
+
+// Copyright (C) 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
+// 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, 51 Franklin Street, Fifth Floor, Boston,
+// MA 02110-1301, USA.
+
+// { dg-do compile }
+
+// libstdc++/23871
+
+#include <iostream>
+
+class mytest {
+public:
+  mytest (int);
+  unsigned char operator|| (const mytest&) const;
+  friend unsigned char operator|| (const int&, const mytest&);
+};
+
+inline unsigned char operator|| (const int& lhs, const mytest& rhs)
+{
+  std::cout << 1 << std::endl;
+  return (mytest)lhs || rhs;
+}
--- /dev/null	2004-06-24 11:06:20.000000000 -0700
+++ libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/7.cc	2005-09-14 16:13:41.000000000 -0700
@@ -0,0 +1,68 @@
+// 2005-07-11  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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 27.6.2.5.2  Arithmetic inserters
+
+#include <sstream>
+#include <testsuite_hooks.h>
+
+void test01()
+{
+  using namespace std;
+  bool test __attribute__((unused)) = true;
+
+  stringstream ostr1, ostr2, ostr3, ostr4;
+
+  ostr1.setf(ios_base::oct);
+  ostr1.setf(ios_base::hex);
+
+  short s = -1;
+  ostr1 << s;
+  VERIFY( ostr1.str() == "-1" );
+
+  ostr2.setf(ios_base::oct);
+  ostr2.setf(ios_base::hex);
+
+  int i = -1;
+  ostr2 << i;
+  VERIFY( ostr2.str() == "-1" );
+
+  ostr3.setf(ios_base::oct);
+  ostr3.setf(ios_base::hex);
+
+  long l = -1;
+  ostr3 << l;
+  VERIFY( ostr3.str() == "-1" );
+
+#ifdef _GLIBCXX_USE_LONG_LONG
+  ostr4.setf(ios_base::oct);
+  ostr4.setf(ios_base::hex);
+
+  long long ll = -1LL;
+  ostr4 << ll;
+  VERIFY( ostr4.str() == "-1" );
+#endif
+}
+
+int main()
+{
+  test01();
+  return 0;
+}
--- /dev/null	2004-06-24 11:06:20.000000000 -0700
+++ libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/wchar_t/7.cc	2005-09-14 16:14:04.000000000 -0700
@@ -0,0 +1,68 @@
+// 2005-07-11  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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 27.6.2.5.2  Arithmetic inserters
+
+#include <sstream>
+#include <testsuite_hooks.h>
+
+void test01()
+{
+  using namespace std;
+  bool test __attribute__((unused)) = true;
+
+  wstringstream ostr1, ostr2, ostr3, ostr4;
+
+  ostr1.setf(ios_base::oct);
+  ostr1.setf(ios_base::hex);
+
+  short s = -1;
+  ostr1 << s;
+  VERIFY( ostr1.str() == L"-1" );
+
+  ostr2.setf(ios_base::oct);
+  ostr2.setf(ios_base::hex);
+
+  int i = -1;
+  ostr2 << i;
+  VERIFY( ostr2.str() == L"-1" );
+
+  ostr3.setf(ios_base::oct);
+  ostr3.setf(ios_base::hex);
+
+  long l = -1;
+  ostr3 << l;
+  VERIFY( ostr3.str() == L"-1" );
+
+#ifdef _GLIBCXX_USE_LONG_LONG
+  ostr4.setf(ios_base::oct);
+  ostr4.setf(ios_base::hex);
+
+  long long ll = -1LL;
+  ostr4 << ll;
+  VERIFY( ostr4.str() == L"-1" );
+#endif
+}
+
+int main()
+{
+  test01();
+  return 0;
+}


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