bsoncxx::builder::stream::single_context is written to accept a single value to be appended to the stream, but it is currently possible to append multiple values through use of open_document and open_array:
using namespace bsoncxx::builder::stream; auto doc = document{} << "x" << [](single_context s) { s << open_array << 0 << close_array << open_array << 1 << close_array; } << finalize;
The above code currently compiles, and throws an exception with a confusing message "expected a key but found none" at runtime. Instead, this code should not compile.
The code erroneously compiles due to the fact that the following functions have the wrong return type. The return type of these functions are currently key_context<single_context> and array_context<single_context>, respectively, but they should be key_context<closed_context> and array_context<closed_context> instead.
- bsoncxx::builder::stream::single_context::operator<<(open_document_type)
- bsoncxx::builder::stream::single_context::operator<<(open_array_type)