How to find out the number of a C++ warning

本小妞迷上赌 提交于 2019-12-24 02:24:04

问题


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 )

But of some, I can't possibly find the corresponding number. For example, I want to disable a:

warning : array subscript is of type 'char' [-Wchar-subscripts]

How do I find its number? Is there a searchable list? The Microsoft documentation isn't searchable on keyword, only on number.


回答1:


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 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

Note that it says “GCC” because the pragma actually works with GCC and Clang.



来源:https://stackoverflow.com/questions/47417179/how-to-find-out-the-number-of-a-c-warning

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!