Obviously this wouldn't be too hard to "fix". There are two opposite views on handling undefined situations. One is to treat them as indications that the programmer overlooked something and trap them as soon as possible, while the other is do what the programmer most likely intends. My personal view is the former. Hence, I would prefer to trap such a situation as an error. Robert Ramey Andrew B wrote:
Let me first say "thanks" to everyone involved in Boost, particularly the serialization library. I am continuously impressed with the quality of this project.
That said, I think I've encountered an issue that I would label as a bug, but perhaps there's something I'm missing.
The following code throws/fails in Visual C++ 7.1 debug build.
void boolTest() { bool uninitializedBool1, uninitializedBool2; std::ofstream ofs( "booltest.txt" ); boost::archive::text_oarchive oa( ofs, boost::archive::no_header ); oa << uninitializedBool1; oa << uninitializedBool2; ofs.close();
std::ifstream ifs( "booltest.txt" ); boost::archive::text_iarchive ia( ifs, boost::archive::no_header ); ia >> uninitializedBool1; ia >> uninitializedBool2; ifs.close(); }
The reason is clear if you look at the contents of booltest.txt: 204 204
Since those bools are uninitialized, VC has written its standard "garbage" to their contents, which gets serialized as a value other than 0 or 1, which is what what the text_iarchive / ifstream would expect to see. I'm not sure if there's a philosophical opposition to supporting serializing uninitialized data, but the other primitives seem to work, and in my experience, it's not unusual to not initialize ever member of a struct before needing to serialize it.
Thanks for your time, Andrew