libstdc++ ensures that cin/cout/cerr are constructed before they are used, but the scheme fails when using constructor priorities. Constructors with a priority are run before constructors without a priority, which is the appropriate behaviour. However, this means that this program:
#include <iostream> void f1() __attribute__ ((constructor (101))); void f1() { std::cout << "f1" << std::endl; } int main() { } will crash at runtime. f1 will be run at a user level priority, but it will run before std::cout is initialized. I suggest that on systems which support constructor priorities, that we arrange to run ios_base::Init::Init() at a high priority. The destructor should also be run at a high priority, of course. -- Summary: cin/cout/cerr constructors should run at high priority when possible Product: gcc Version: 4.5.0 Status: UNCONFIRMED Severity: enhancement Priority: P3 Component: libstdc++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: ian at airs dot com http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39796