Hi all, If I use cerr/cout... before main function, it may potentially cause use-before-init before this patch.
This is a tiny patch, but important to guarantee init-before-use. Please review it. Thanks!! === Long explanation: std::cout, cerr, ... are global objects that should be initialized before use. However, C++ does not guarantee an order of initialization between static objects in different translation units. One basic idiom is that declares a static object that gets created in every translation unit that includes <iostream>. This object has a static constructor and destructor that initializes and destroys the global iostream objects before they could possibly be used in the file. In GNU libstdc++, it is at <libstdc++>/include/std/iostream: static ios_base::Init __ioinit; but in libcxx, it is at src/iostream.cpp, i.e., it only guarantee initialized when entering main function. If we use them before main, it may cause undefined behavior since it is a use-before-init bug. Thanks! -- Best Regards, WenHan Gu (Nowar)
libcxx.patch
Description: Binary data
_______________________________________________ cfe-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
