xcode 如何使用#pragma clang 诊断

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20078941/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 04:18:49  来源:igfitidea点击:

how to use #pragma clang diagnostics

xcodeclangpragmadiagnostics

提问by Johnykutty

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

我知道#pragma clang 诊断可用于忽略由 clang 生成的一些警告。但我不知道如何正确使用它。

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)

但我不知道如何为忽略的#pragma clang 诊断获取正确的参数(此处为“-Wunused-variable”)

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

有什么办法可以为 xcode 的特定警告指定这种警告名称?

回答by iOS Gamer

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

右键单击问题导航器中的问题,然后选择“在日志中显示”。错误消息将指定警告。

回答by AndiDog

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

如果您知道以下消息,则可以查找警告命令行参数:Clang 中的诊断标志

回答by Abo3atef

Ok, then this is what I understood

好吧,这就是我的理解

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

Clang是编译器的 C/Objective C 前端层。和 Clang 负责显示我们在 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..

因此,当您在 Xcode 中启用将警告视为错误的选项时,在某些情况下,您需要一个工具来解决 Clang 以允许出现一些警告。

and here Clang Diagnosticsplay that role..

在这里Clang Diagnostics扮演那个角色..

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

其机制就像Graph Matrix,它以Stack方式发生..Push和Pop..

so when you have something like this..

所以当你有这样的事情时..

#pragma clang diagnostic push

#pragma clang diagnostic push

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

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

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

// 代码.........

#pragma clang diagnostic pop

#pragma clang diagnostic pop

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

您正在阻止 Clang 在该区域显示警告消息,因此它类似于 SafeArea ..

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

你可以在这里找到更多可以避免的 Clang 警告.. http://fworingclangwarnings.com