Yakk - Adam Nevraumont
Yakk - Adam Nevraumont

Reputation: 275800

#pragma warning clang/msvc compatibility

I'm writing some clang/msvc cross-compatible code.

It has come to my attention that clang does not treat this as an unknown warning:

#pragma warning(disable:4444)

(where 4444 is just an example; the actual disabled warnings are manyfold)

Is clang's (clang-c2 and llvm) interpretation of that #pragma disabling a warning at all similar to what cl.exe interprets the warning to be disabled?

Or are the numbers unrelated?

Upvotes: 2

Views: 3797

Answers (1)

Richard Hodges
Richard Hodges

Reputation: 69912

Not an answer, but too long to put as a comment.

The only mention I could find about implemented #pragma compatibility is here:

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.

No mention of #pragma warning, so I would suspect that it's silently ignored unless there's more information somewhere.

No idea how to test it, as I don't understand what conditions would produce a 4444 warning.

Also on that page:

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.

Upvotes: 3

Related Questions