[PATCH] 4.0 fix for libstdc++/23871

Janis Johnson janis187@us.ibm.com
Wed Sep 14 00:24:00 GMT 2005


Paolo and Benjamin have both said offline that this backport from
mainline to the 4.0 branch (when it reopens) is OK, but this is the
first time I've written a test for libstdc++; is this the right
location for it, and does it need anything else in the comments?

2005-09-13  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/5.cc: New.

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/5.cc	2005-09-13 17:09:19.000000000 -0700
@@ -0,0 +1,38 @@
+// 2005-09-13  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;
+}



More information about the Libstdc++ mailing list