我可以在 VS 中使用 GCC/LLVM 的 STL headers 吗?

Can I use GCC's / LLVM's STL headers with VS?

我使用的是 MSVC++ 2013,我安装了 Clang 插件。

但是,由于我使用的是 STL,I'm getting bugs like this one:

In file included from C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\map:6:
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\xtree(1667,3) :  error: cannot compile this try statement yet
            _TRY_BEGIN
            ^~~~~~~~~~

数量不少。事实上,只有 header 文件有问题——这正是让我感到困惑的地方。

这是真正的编译器错误吗?与 MS 的 STL 实现不兼容?

如果是这样,我可以修复它吗?如何修复?

我想过使用 GCC 或 LLVM 的 headers,但我不知道如何做 -- 任何指点将不胜感激。

我不认为llvm的libc++可以用msvc编译。您最好的选择是尝试使用 LLVM 生成 MSVC 兼容代码,这些代码可以(理论上)与 Visual C++ 编译代码链接。

http://clang.llvm.org/docs/MSVCCompatibility.html

既然你坚持环境设置正确,我就查了一下那个不明白的确切宏。当 MSVC headers 本身包含 xstddef 而 _HAS_EXCEPTIONS 定义为 0 时,可能会发生该特定错误。我在该宏上找不到任何其他条件,因此您的 clang 似乎正在无一例外地进行编译。

这在我脑海中敲响了警钟,Clang 在 windows 上长期以来一直存在异常问题。根据这个link,它仍然在MSVC兼容模式下:"Exceptions and SEH: Minimal. Clang can parse both constructs, but does not know how to emit compatible handlers. Clang cannot throw exceptions but it can rethrow them." http://clang.llvm.org/docs/MSVCCompatibility.html