.. raw:: html .. role:: none .. role:: partial .. role:: good ================== MSVC compatibility ================== When Clang compiles C++ code for Windows, it attempts to be compatible with MSVC. There are multiple dimensions to compatibility. First, Clang attempts to be ABI-compatible, meaning that Clang-compiled code should be able to link against MSVC-compiled code successfully. However, C++ ABIs are particularly large and complicated, and Clang's support for MSVC's C++ ABI is a work in progress. If you don't require MSVC ABI compatibility or don't want to use Microsoft's C and C++ runtimes, the mingw32 toolchain might be a better fit for your project. Second, Clang implements many MSVC language extensions, such as ``__declspec(dllexport)`` and a handful of pragmas. These are typically controlled by ``-fms-extensions``. Third, MSVC accepts some C++ code that Clang will typically diagnose as invalid. When these constructs are present in widely included system headers, Clang attempts to recover and continue compiling the user's program. Most parsing and semantic compatibility tweaks are controlled by ``-fms-compatibility`` and ``-fdelayed-template-parsing``, and they are a work in progress. Finally, there is :ref:`clang-cl`, a driver program for clang that attempts to be compatible with MSVC's cl.exe. ABI features ============ The status of major ABI-impacting C++ features: * Record layout: :good:`Complete`. We've tested this with a fuzzer and have fixed all known bugs. * Class inheritance: :good:`Mostly complete`. This covers all of the standard OO features you would expect: virtual method inheritance, multiple inheritance, and virtual inheritance. Every so often we uncover a bug where our tables are incompatible, but this is pretty well in hand. This feature has also been fuzz tested. * Name mangling: :good:`Ongoing`. Every new C++ feature generally needs its own mangling. For example, member pointer template arguments have an interesting and distinct mangling. Fortunately, incorrect manglings usually do not result in runtime errors. Non-inline functions with incorrect manglings usually result in link errors, which are relatively easy to diagnose. Incorrect manglings for inline functions and templates result in multiple copies in the final image. The C++ standard requires that those addresses be equal, but few programs rely on this. * Member pointers: :good:`Mostly complete`. Standard C++ member pointers are fully implemented and should be ABI compatible. Both `#pragma pointers_to_members`_ and the `/vm`_ flags are supported. However, MSVC supports an extension to allow creating a `pointer to a member of a virtual base class`_. Clang does not yet support this. .. _#pragma pointers_to_members: http://msdn.microsoft.com/en-us/library/83cch5a6.aspx .. _/vm: http://msdn.microsoft.com/en-us/library/yad46a6z.aspx .. _pointer to a member of a virtual base class: http://llvm.org/PR15713 * Debug info: :partial:`Minimal`. Clang emits CodeView line tables into the object file, similar to what MSVC emits when given the ``/Z7`` flag. Microsoft's link.exe will read this information and use it to create a PDB, enabling stack traces in all modern Windows debuggers. Clang does not emit any type info or description of variable layout. * RTTI: :good:`Complete`. Generation of RTTI data structures has been finished, along with support for the ``/GR`` flag. * Exceptions and SEH: :none:`Unstarted`. Clang can parse both constructs, but does not know how to emit compatible handlers. * Thread-safe initialization of local statics: :none:`Unstarted`. We are ABI compatible with MSVC 2013, which does not support thread-safe local statics. MSVC "14" changed the ABI to make initialization of local statics thread safe, and we have not yet implemented this. * Lambdas: :good:`Mostly complete`. Clang is compatible with Microsoft's implementation of lambdas except for providing overloads for conversion to function pointer for different calling conventions. However, Microsoft's extension is non-conforming. Template instantiation and name lookup ====================================== In addition to the usual `dependent name lookup FAQs`_, Clang is often unable to parse certain invalid C++ constructs that MSVC allows. As of this writing, Clang will reject code with missing ``typename`` annotations: .. _dependent name lookup FAQs: http://clang.llvm.org/compatibility.html#dep_lookup .. code-block:: c++ struct X { typedef int type; }; template int f() { // missing typename keyword return sizeof(/*typename*/ T::type); } template void f(); Accepting code like this is ongoing work. Ultimately, it may be cleaner to `implement a token-based template instantiation mode`_ than it is to add compatibility hacks to the existing AST-based instantiation. .. _implement a token-based template instantiation mode: http://llvm.org/PR18714