I'm having trouble understanding what's going on here. Is this a bug in G++ or possible is the C++ standard a little bit funny, or is it STL? Perhaps, the result of this code undefined due to the temporary?
I would have expected as output Hello Hello The rationale for this example is the following: I'd like to write a log class that extends an ostream and I want to use roughly like this: LogEntry(INFO) << "MyMessage" << LogEntry::commit; #include <sstream> #include <iostream> int main() { ::std::ostringstream ss; ss << "Hello" ; ::std::cerr << ss.str() << ::std::endl; ::std::string s = static_cast< ::std::ostringstream&>(::std::ostringstream() << "Hello2").str(); ::std::cerr << s << ::std::endl; return 0; } -- Summary: funny ::std::ostream behavior when using a temporary Product: gcc Version: 4.0.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: Raimund dot Merkert at baesystems dot com http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26040