how to use #pragma clang diagnostics

两盒软妹~` 提交于 2019-11-29 06:42:47

问题


I know that #pragma clang diagnostics can be used for ignoring some warnings generated by clang. But I don't know how to use this correctly.

For example, for an unused variable warning we can avoid warning by

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-variable"

int number;

#pragma clang diagnostic pop

But I don't know how to get correct parameter for #pragma clang diagnostic ignored ("-Wunused-variable" here)

Is there any way to fing this kind of warning name for specific warnings with xcode?


回答1:


Right click on the issue in the issue navigator and select "Reveal in Log". The error message will specify the warning.




回答2:


You can look up the warning command line parameter if you know the message: Diagnostic flags in Clang




回答3:


Ok, then this is what I understood

Clang is the C/Objective C Front end Layer for compiler. and Clang take the responsibility of showing Warning and Error message that we see in Xcode.

So when you enable the option of treat your warning as Error in Xcode, In some cases you need a tool to work around about the Clang to allow some warnings..

and here Clang Diagnostics play that role..

and the mechanism for that is like Graph Matrix, which is happened in Stack way..Push and Pop..

so when you have something like this..

#pragma clang diagnostic push

#pragma clang diagnostic ignored "-Wcovered-switch-default"

// Code.........

#pragma clang diagnostic pop

you are preventing Clang to show warning messages on that area, so it something like SafeArea..

and you can find more Clang Warning that you can avoid here.. http://fuckingclangwarnings.com



来源:https://stackoverflow.com/questions/20078941/how-to-use-pragma-clang-diagnostics

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