This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
libstdc++/5268: More fun with global stream destruction semantics
- From: theonetruekenny at yahoo dot com
- To: gcc-gnats at gcc dot gnu dot org
- Cc: kenny dot simpson at gs dot com
- Date: 3 Jan 2002 22:33:27 -0000
- Subject: libstdc++/5268: More fun with global stream destruction semantics
- Reply-to: theonetruekenny at yahoo dot com
>Number: 5268
>Category: libstdc++
>Synopsis: More fun with global stream destruction semantics
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Thu Jan 03 14:36:00 PST 2002
>Closed-Date:
>Last-Modified:
>Originator: Kenny Simpson
>Release: cvs - probably also in 3.0
>Organization:
>Environment:
source
>Description:
Similar to PR 3045, in fact same example used.
The problem is that in ios.cc lines [190, 192] and [197, 199]
the flush method is called on the global stream objects cout, cerr, clog, etc
The reason this is a problem is that this will call methods on the
underlying stream buffer, which may no longer exist at this point.
(e.g. is the stream were redirected)
>How-To-Repeat:
// mostly copied from PR 3045
#include <fstream>
#include <iostream>
std::basic_filebuf b1;
int main()
{
b1.open("foo");
cout.rdbuf( b1 );
std::cout << "hello\n";
return 0;
}
// order of events:
// magic std::ios_base::Init object is constructed causing
// std::buf_cout constructed - BTW should this even be in std?
// std::cout constructed to point at std::buf_cout
// b1 is created
// main begins
// std::cout is redirected to b1
// main ends
// b1 is destroyed
// magic std::ios_base::Init object destroyed causing
// std::cout.flush, which in turn calls pubsync on b1 - oops
>Fix:
Don't call .flush on cout, cerr, clog, etc..
>Release-Note:
>Audit-Trail:
>Unformatted: