Bug in endl (libio)

jlquinn@us.ibm.com jlquinn@us.ibm.com
Fri May 19 14:41:00 GMT 2000

In libio/iostream.cc, endl() should check if the stream can accept chars
before writing its eol.  I found this because I was forcibly setting a
stream to eof in order to create a null stream that swallows chars (long
story - NT has a less than stellar iostream).  In that situation, eols
still get written.

This is true in 2.95.2 as well as the latest cvs according to the web

Here's a patch:

--- /usr/project/gcc/iostream.cc.orig    Fri May 19 17:37:57 2000
+++ /usr/project/gcc/iostream.cc   Fri May 19 17:40:36 2000
@@ -963,7 +963,9 @@

 ostream& endl(ostream& outs)
-    return flush(outs.put('\n'));
+    if (opfx)
+        flush(outs.put('\n'));
+    return outs;

 istream& lock(istream& ins)

Jerry Quinn

More information about the Gcc-bugs mailing list