简体   繁体   English

VS2015:从CLI使用/ Wall但在某些文件中禁用警告(例如:在Microsoft Visual Studio 14.0中使用)

[英]VS2015: using /Wall from the CLI but disabling warning in some file (eg: thoses in Microsoft Visual Studio 14.0)

I wanted to enable the /Wall option using the Command line and IncrediBuild, but now I have too many warning from files that are mostly "read only": 我想使用命令行和IncrediBuild启用/Wall选项,但现在我从大多数“只读”的文件中收到太多警告:

C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath(35): warning C4514: 'abs': unreferenced inline function has been removed

I don't/won't touch cmath but still I've got those picky warning (which I asked). 我不会/不会接触到cmath,但我仍然有那些挑剔的警告(我问过)。

Is there a way to tell VS2015 to ignore warning in certain directories? 有没有办法告诉VS2015忽略某些目录中的警告? (like if I were using a pragma inside those file to locally disable such warning). (就像我在这些文件中使用pragma本地禁用此类警告一样)。

Note: it was perhaps not clear, but I don't want to use a trick such as modifying local source (that's a big project with at least 1000 cpp files) or system header. 注意:它可能不太清楚,但我不想使用诸如修改本地源(这是一个至少有1000个cpp文件的大项目)或系统头的技巧。 Only through the command line. 只能通过命令行。

What I do is wrap all the system includes with #pragma warning push / pop . 我所做的是用#pragma warning push / pop包装所有系统包含的内容。 I have convenience macros for that in my library . 我的库中有方便的宏。

Usage example: 用法示例:

#include "compiler/compiler_warnings_control.h"

// The following header files belong to a 3rd-party library.
// These headers produce various compiler warnings.
// So I simply wrap them in warning suppression macros:

DISABLE_COMPILER_WARNINGS
#include "libusb.h"
#include "zlib.h"
RESTORE_COMPILER_WARNINGS

Implementation (MSVC part only; the complete implementation in my repo is cross-platform): 实现(仅限MSVC部分;我的仓库中的完整实现是跨平台的):

#define COMPILER_PRAGMA(text) __pragma(text)
#define STORE_COMPILER_WARNINGS COMPILER_PRAGMA(warning(push))
#define RESTORE_COMPILER_WARNINGS COMPILER_PRAGMA(warning(pop))
#define DISABLE_SPECIFIC_COMPILER_WARNING(warningCode) COMPILER_PRAGMA(warning (diable: warningCode))

#define DISABLE_COMPILER_WARNINGS COMPILER_PRAGMA(warning(push, 0)) // Set /W0

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM