Remove __cdecl from exported symbol declarations

XMLWordPrintableJSON

    • Type: Task
    • Resolution: Unresolved
    • Priority: Unknown
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • C Drivers
    • None
    • None
    • None
    • None
    • None
    • None

      Drop support for alternative default calling conventions by removing __cdecl from exported symbol declarations. Users setting alternative default calling conventions (for either the MongoDB C++ Driver libraries or for downstream projects) should be capable of ensuring default calling convention consistency. The maintenance burden of continuing to support and test __cdecl calling convention of exported symbols regardless of alternative default calling conventions is not worthwhile.

      Motivated by this discussion thread.

      Note: per Visual Studio 2015 documentation (the current minimum required VS version), quote:

      __cdecl is the default calling convention for C and C++ programs. ... On ARM and x64 processors, __cdecl is accepted but typically ignored by the compiler. By convention on ARM and x64, arguments are passed in registers when possible, and subsequent arguments are passed on the stack. ... Because the C naming and calling conventions are the default, the only time you must use __cdecl in x86 code is when you have specified the /Gv (vectorcall), /Gz (stdcall), or /Gr (fastcall) compiler option. The /Gd compiler option forces the __cdecl calling convention.

      Downstream projects using an alternative default calling convention will need to compile translation units which include MongoDB C++ Driver library headers with the same default calling convention as what was used to build the libraries to be linked. This can be done on a per-TU basis with its external linkage functions explicitly declared with their own projects' alternative default calling convention.

      e.g. if the MongoDB C++ Driver libraries were built with __cdecl (the default), a downstream project building with __vectorcall must:

      set_property (SOURCE "user/code.cpp" PROPERTY COMPILE_OPTIONS "/Gd")
      

      and:

      // user/code.cpp with __cdecl default.
      #include <mongocxx/instance.hpp>
      
      namespace user {
      
      void __vectorcall code() { ... } // For other user code with __vectorcall default.
      
      } // namespace user
      

      Conversely, if the MongoDB C++ Driver libraries were built with __vectorcall, a downstream project building with __cdecl must:

      set_property (SOURCE "user/code.cpp" PROPERTY COMPILE_OPTIONS "/Gv")
      

      and:

      // user/code.cpp with __vectorcall default.
      #include <mongocxx/instance.hpp>
      
      namespace user {
      
      void __cdecl code() { ... } // For other user code with __cdecl default.
      
      } // namespace user
      

            Assignee:
            Unassigned
            Reporter:
            Ezra Chung
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: