Uploaded image for project: 'C++ Driver'
  1. C++ Driver
  2. CXX-1246

bsoncxx::builder::stream::single_context should not permit appending of multiple values

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 3.2.0-rc0
    • Component/s: API, BSON
    • Labels:
      None

      Description

      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)

        Attachments

          Activity

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: