c++ - #pragma 警告 clang/msvc 兼容性

标签 c++ clang llvm-clang pragma

我正在编写一些 clang/msvc 交叉兼容代码。

我注意到 clang 不会将此视为未知警告:

#pragma warning(disable:4444)

(其中 4444 只是一个示例;实际禁用的警告有很多)

clang(clang-c2 和 llvm)对 #pragma 禁用警告的解释是否完全类似于 cl.exe 解释警告被禁用的内容?

或者这些数字不相关?

最佳答案

不是答案,但太长无法作为评论。

我能找到的关于实现的#pragma 兼容性的唯一提及是在这里:

http://releases.llvm.org/3.6.2/tools/docs/UsersManual.html

clang supports the Microsoft #pragma pack feature for controlling record layout. GCC also contains support for this feature, however where MSVC and GCC are incompatible clang follows the MSVC definition.

clang supports the Microsoft #pragma comment(lib, "foo.lib") feature for automatically linking against the specified library. Currently this feature only works with the Visual C++ linker.

clang supports the Microsoft #pragma comment(linker, "/flag:foo") feature for adding linker flags to COFF object files. The user is responsible for ensuring that the linker understands the flags.

没有提到#pragma warning,所以我怀疑它被默默地忽略了,除非某处有更多信息。

不知道如何测试它,因为我不明白什么情况会产生 4444 警告。

也在那个页面上:

Microsoft extensions

clang has some experimental support for extensions from Microsoft Visual C++; to enable it, use the -fms-extensions command-line option. This is the default for Windows targets. Note that the support is incomplete. Some constructs such as dllexport on classes are ignored with a warning, and others such as Microsoft IDL annotations are silently ignored.

clang has a -fms-compatibility flag that makes clang accept enough invalid C++ to be able to parse most Microsoft headers. For example, it allows unqualified lookup of dependent base class members, which is a common compatibility issue with clang. This flag is enabled by default for Windows targets.

关于c++ - #pragma 警告 clang/msvc 兼容性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41637194/

相关文章:

c - tcc 中的空指针检测

c++ - 如何让 C++0x/C++11 风格的基于范围的 for 循环与 clang 一起使用?

c++ - 如何使用 llvm 库

c++ - 获取 LLVM 模块中的所有值

c++ - Clang5.0 : previous declaration in "__hash_table"

c++ - 为包含 typedef 的类型专门化模板

c++ - 使用 Opencv C++ 对循环进行矢量化

C++简单读取注册表问题

python - 如何在 Python 中解析 C 格式字符串?

c++ - 在哪里可以找到适用于全屏模式的 Windows Vista 免费编译器?