[iostreams] filtering_ostream does not flush std::cout.

I'm using Boost 1.43.0, and I've found that filtering_ostream does not
flush "std::cout". I found a relevant (and recent) ticket against
Boost 1.44.0, but my issue is slightly different.
https://svn.boost.org/trac/boost/ticket/4590
I'm using GCC 4.3.4 on Gentoo Linux.
I'm hoping that I'm just doing something wrong, but if you think
there's a bug, I'll add my testcase to the ticket.
The basic recipe:
filtering_ostream out;
out.push(any_filter_at_all());
out.push(std::cout);
out << "Hello World!" << std::flush;
sleep(10); // Observe an empty console.
std::cout << std::flush;
sleep(10); // Observe printed text on console.
This problem is quite bad for me when doing the following on the
command-line (for a more complicated program):
./program 2>&1 | tee some-file.log
Because stdout is not getting flushed, the stdout and stderr get
intermingled strangely.
However, disabling buffering on stdout works around the problem:
stdbuf --output=0 ./program 2>&1 | tee some-file.log
Please tell me if you think there's a bug in my code. If it's a bug
in Boost.Iostreams (or I'm expecting the wrong behaviour), I would
appreciate any ideas for workarounds (I tried cout.setf(unitbuf), and
that doesn't seem to do the trick).
Here's the full text of my code:
------------------
// Test case for flushing a filtering_ostream based on the
// boost_iostreams_filtering_ostream.cpp attached to ticket #4950:
// https://svn.boost.org/trac/boost/ticket/4590
// https://svn.boost.org/trac/boost/attachment/ticket/4590/boost_iostreams_filt...
// changed to use "cout" as the sink.
//
// Flushing a filtering_ostream using the flush() global function does not work
// in Boost 1.43. I suspect it also does not work in Boost 1.44.
//
// Using GCC-4.3.4 on Gentoo Linux.
//
#include <cassert>
#include <string>
#include
participants (1)
-
Duncan Smith