Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-80330

IDL generate noncompilable c++ code in case of a chained optional variant field

    • Service Arch
    • Fully Compatible
    • ALL
    • Sharding EMEA 2023-09-18

      Currently experiencing the idl generator to generate c++ code that doesn't compile in case of a chained Struct that contains an optional variant field between a generic type and a customised struct

      Reproducible idl example

       

      global:
          cpp_namespace: "mongo"
      imports:
          - "mongo/db/basic_types.idl"
          
      structs:
          Point:
              description: "A struct which will be part of the variant type"
              strict: true
              fields:
                  x:
                      type: int
                      stability: stable
                  y:
                      type: int
                      stability: stable
       
          Data:
              description: "Just some data"
              strict: false
              fields:
                broken_field:
                  description: "The field that will cause c++ generated code not to compile"
                  type:
                      variant: [bool, Point]
                  optional: true
                  stability: stable
       
      commands:
          mycommand:
              description: "A command"
              command_name: mycommand
              namespace: concatenate_with_db
              cpp_name: MyCommand
              api_version: ""
              strict: true
              reply_type: OkReply
              inline_chained_structs: true
              chained_structs:
                Data: Data
       
      

      The generated code will cause this snippet not to compile

       

      switch (variantType) {
                          case Bool:
                          {
                              _data.setBroken_field(boost::optional<stdx::variant<bool, mongo::Point>>(element.boolean()));
                              break;
                          }
                          case Object:
                              _data.setBroken_field(mongo::Point::parse(ctxt, element.Obj())); // <------------- this does not compile because it's missing a cast
                              break;
                          default:
                              ctxt.throwBadType(element, {BSONType::Bool});
                              break;
                          }
                          continue;
      

       

            Assignee:
            pierlauro.sciarelli@mongodb.com Pierlauro Sciarelli
            Reporter:
            enrico.golfieri@mongodb.com Enrico Golfieri
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: