2014-03-01 07:46:04 +08:00
|
|
|
.. raw:: html
|
|
|
|
|
|
|
|
<style type="text/css">
|
|
|
|
.none { background-color: #FFCCCC }
|
|
|
|
.partial { background-color: #FFFF99 }
|
|
|
|
.good { background-color: #CCFF99 }
|
|
|
|
</style>
|
|
|
|
|
|
|
|
.. 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++
|
2014-07-03 05:46:03 +08:00
|
|
|
ABIs are particularly large and complicated, and Clang's support for MSVC's C++
|
2014-03-01 07:46:04 +08:00
|
|
|
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``.
|
|
|
|
|
2014-03-06 04:18:59 +08:00
|
|
|
Third, MSVC accepts some C++ code that Clang will typically diagnose as
|
2014-03-01 07:46:04 +08:00
|
|
|
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.
|
|
|
|
|
2014-03-06 04:18:59 +08:00
|
|
|
Finally, there is :ref:`clang-cl`, a driver program for clang that attempts to
|
|
|
|
be compatible with MSVC's cl.exe.
|
|
|
|
|
2014-03-01 07:46:04 +08:00
|
|
|
ABI features
|
|
|
|
============
|
|
|
|
|
|
|
|
The status of major ABI-impacting C++ features:
|
|
|
|
|
2014-07-03 01:26:04 +08:00
|
|
|
* Record layout: :good:`Complete`. We've tested this with a fuzzer and have
|
|
|
|
fixed all known bugs.
|
2014-03-01 07:46:04 +08:00
|
|
|
|
|
|
|
* 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
|
2014-07-03 01:26:04 +08:00
|
|
|
our tables are incompatible, but this is pretty well in hand. This feature
|
|
|
|
has also been fuzz tested.
|
2014-03-01 07:46:04 +08:00
|
|
|
|
|
|
|
* 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
|
|
|
|
|
2014-11-25 14:59:35 +08:00
|
|
|
* Debug info: :partial:`Minimal`. Clang emits both CodeView line tables
|
|
|
|
(similar to what MSVC emits when given the ``/Z7`` flag) and DWARF debug
|
|
|
|
information into the object file.
|
|
|
|
Microsoft's link.exe will transform the CodeView line tables into a PDB,
|
2014-03-01 07:46:04 +08:00
|
|
|
enabling stack traces in all modern Windows debuggers. Clang does not emit
|
2014-11-25 14:59:35 +08:00
|
|
|
any CodeView-compatible type info or description of variable layout.
|
|
|
|
Binaries linked with either binutils' ld or LLVM's lld should be usable with
|
|
|
|
GDB however sophisticated C++ expressions are likely to fail.
|
2014-03-01 07:46:04 +08:00
|
|
|
|
2014-07-03 05:09:33 +08:00
|
|
|
* RTTI: :good:`Complete`. Generation of RTTI data structures has been
|
2014-07-03 01:26:04 +08:00
|
|
|
finished, along with support for the ``/GR`` flag.
|
2014-03-01 07:46:04 +08:00
|
|
|
|
2014-11-25 15:20:20 +08:00
|
|
|
* Exceptions and SEH: :partial:`Minimal`. Clang can parse both constructs, but
|
2015-03-12 02:38:51 +08:00
|
|
|
does not know how to emit compatible handlers. Clang can throw and rethrow
|
|
|
|
C++ exceptions.
|
2014-03-01 07:46:04 +08:00
|
|
|
|
|
|
|
* Thread-safe initialization of local statics: :none:`Unstarted`. We are ABI
|
2014-07-03 01:26:04 +08:00
|
|
|
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,
|
2014-03-01 07:46:04 +08:00
|
|
|
and we have not yet implemented this.
|
|
|
|
|
2014-07-03 06:14:34 +08:00
|
|
|
* Lambdas: :good:`Mostly complete`. Clang is compatible with Microsoft's
|
2014-07-03 01:26:04 +08:00
|
|
|
implementation of lambdas except for providing overloads for conversion to
|
|
|
|
function pointer for different calling conventions. However, Microsoft's
|
|
|
|
extension is non-conforming.
|
2014-03-01 07:46:04 +08:00
|
|
|
|
|
|
|
Template instantiation and name lookup
|
|
|
|
======================================
|
|
|
|
|
2014-07-03 07:37:33 +08:00
|
|
|
MSVC allows many invalid constructs in class templates that Clang has
|
|
|
|
historically rejected. In order to parse widely distributed headers for
|
|
|
|
libraries such as the Active Template Library (ATL) and Windows Runtime Library
|
|
|
|
(WRL), some template rules have been relaxed or extended in Clang on Windows.
|
|
|
|
|
|
|
|
The first major semantic difference is that MSVC appears to defer all parsing
|
|
|
|
an analysis of inline method bodies in class templates until instantiation
|
|
|
|
time. By default on Windows, Clang attempts to follow suit. This behavior is
|
|
|
|
controlled by the ``-fdelayed-template-parsing`` flag. While Clang delays
|
|
|
|
parsing of method bodies, it still parses the bodies *before* template argument
|
|
|
|
substitution, which is not what MSVC does. The following compatibility tweaks
|
2015-03-13 03:35:34 +08:00
|
|
|
are necessary to parse the template in those cases.
|
2014-07-03 07:37:33 +08:00
|
|
|
|
|
|
|
MSVC allows some name lookup into dependent base classes. Even on other
|
|
|
|
platforms, this has been a `frequently asked question`_ for Clang users. A
|
|
|
|
dependent base class is a base class that depends on the value of a template
|
|
|
|
parameter. Clang cannot see any of the names inside dependent bases while it
|
|
|
|
is parsing your template, so the user is sometimes required to use the
|
|
|
|
``typename`` keyword to assist the parser. On Windows, Clang attempts to
|
|
|
|
follow the normal lookup rules, but if lookup fails, it will assume that the
|
|
|
|
user intended to find the name in a dependent base. While parsing the
|
|
|
|
following program, Clang will recover as if the user had written the
|
|
|
|
commented-out code:
|
|
|
|
|
|
|
|
.. _frequently asked question:
|
2014-03-01 07:46:04 +08:00
|
|
|
http://clang.llvm.org/compatibility.html#dep_lookup
|
|
|
|
|
|
|
|
.. code-block:: c++
|
|
|
|
|
2014-07-03 07:37:33 +08:00
|
|
|
template <typename T>
|
|
|
|
struct Foo : T {
|
|
|
|
void f() {
|
|
|
|
/*typename*/ T::UnknownType x = /*this->*/unknownMember;
|
|
|
|
}
|
2014-03-01 07:46:04 +08:00
|
|
|
};
|
|
|
|
|
2014-07-03 07:37:33 +08:00
|
|
|
After recovery, Clang warns the user that this code is non-standard and issues
|
|
|
|
a hint suggesting how to fix the problem.
|
2014-03-01 07:46:04 +08:00
|
|
|
|
2014-07-03 07:37:33 +08:00
|
|
|
As of this writing, Clang is able to compile a simple ATL hello world
|
|
|
|
application. There are still issues parsing WRL headers for modern Windows 8
|
|
|
|
apps, but they should be addressed soon.
|