This is the mail archive of the
libstdc++@sourceware.cygnus.com
mailing list for the libstdc++ project.
Re: Revised patch
> No, it is not explicitly required. What is required: cin/cout/cerr/clog
> are properly initialized before other iostream objects are used.
No, even that isn't required. [lib.iostream.objects]/2 says
>> The objects are constructed, and the associations are established
>> at some time prior to or during first time an object of class
>> basic_ios<charT,traits>::Init is constructed, and in any case
>> before the body of main begins execution.264)
So, an application can only rely on initialzed cin/* after creating
and instance of basic_ios::Init. For example, the code
#include <iostream>
using namespace std;
struct A{
A(){cout<<"Initializing"<<endl;}
};
A a;
has undefined behavior - constructing ::a might access an
uninitialized object. To correct this bug, the author should write
static ostream::Init dummy;
A a;
Because of that, I don't think that object implicitly instantiated
when including <iostream> is necessary. But then, footnote 264 says
>> If it is possible for them to do so, implementations are encouraged
>> to initialize the objects earlier than required.
So, it doesn't hurt, either.
Regards,
Martin