如何找出C ++警告的数量 [英] How to find out the number of a C++ warning
问题描述
我已在代码中打开 -Wall
来摆脱所有警告。但是有些我想在代码中允许,所以我在代码中禁用了那些。在常见的警告中,我可以轻松地在Google中找到警告编号并将其禁用,例如:
I have turned on -Wall
in my code to get rid of all warnings. Some however I want to allow within the code, so I disable those ones in code. Of the common ones, I can easily find out the warning number in Google and disable them like e.g.:
#pragma warning( disable : 4127 )
但是有些我找不到对应的数字。例如,我要禁用a:
But of some, I can't possibly find the corresponding number. For example, I want to disable a:
warning:数组下标的类型为'char'[-Wchar-subscripts]
如何找到其编号?有可搜索的列表吗? Microsoft文档不可搜索
How do I find its number? Is there a searchable list? The Microsoft documentation isn't searchable on keyword, only on number.
推荐答案
您没有使用Microsoft编译器,或者至少没有使用Microsoft编译器前端。该警告由Clang前端打印。 (GCC发出了非常类似的警告,也称为 -Wchar-subscripts
,但消息的措词略有不同。)
You are not using a Microsoft compiler, or at least not a Microsoft compiler front end. The warning is printed by the Clang front end. (GCC has a very similar warning, also called -Wchar-subscripts
, but the wording of the message is slightly different.)
Clang和GCC不使用数字作为警告,而是使用名称。您可以使用以下编译指示禁用诊断:
Clang and GCC do not use numbers for warnings, but names. You can use these pragmata to disable the diagnostic:
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wchar-subscripts"
随后将在没有警告的情况下进行编译的代码,您可以恢复警告的先前状态(通常启用):
The code which should be compiled without the warning follows, and with this, you can restore the previous state of the warning (typically enabled):
#pragma GCC diagnostic pop
请注意它说 GCC
,因为该实用程序实际上适用于GCC和Clang。
Note that it says "GCC
" because the pragma actually works with GCC and Clang.
这篇关于如何找出C ++警告的数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!