When parsing BSONType::Object elements, the automatically-generated parse method will store a view of BSON in the spec, rather than an owned copy. For example,
The spec then contains garbage if the original object used for parsing goes out-of-scope. Since the IDL already holds other owned types (e.g. std::string), we should strive to keep an owned copy of BSON.
I don't think this affects existing users of the IDL, as in most usages the original command object is kept around for the lifetime of the command's execution. However, we'd like to serialize $out with the IDL in
SERVER-36187, but our reparse-reserialization tests hit a segmentation violation.