xcode 使用 LLVM/Clang 忽略特定文件中的所有警告
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7897429/
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
Ignore all warnings in a specific file using LLVM/Clang
提问by bobbypage
There are some files in my iOS project that have some warnings, and I want to ignore those warnings. I don't want to disable warnings in the entire project (know how to do that), just some specific files. So, is there a way to completely ignore all warnings from a specific file?
我的 iOS 项目中有一些文件有一些警告,我想忽略这些警告。我不想在整个项目中禁用警告(知道如何做到这一点),只是一些特定的文件。那么,有没有办法完全忽略来自特定文件的所有警告?
I'm using LLVM 3.0 and Clang on Xcode 4.2.
我在 Xcode 4.2 上使用 LLVM 3.0 和 Clang。
采纳答案by justin
if you're just using clang, then you should use the pragma syntax for sources you maintain (assuming it is impossible to remove the warning by altering the program appropriately).
如果您只是使用 clang,那么您应该对您维护的源使用 pragma 语法(假设无法通过适当更改程序来删除警告)。
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmultichar"
char b = 'df'; // no warning.
#pragma clang diagnostic pop
if these are programs you cannot change and don't maintain, you should specify the warning(s) to disable for the file, rather than all. to disable all, you can add the per file argument -w
. sources change, and some warnings do (or do not) apply with different build settings. clang's messages can tell you what flag equates to the generated warning.
如果这些是您无法更改和维护的程序,您应该指定要为文件禁用的警告,而不是全部。要禁用所有,您可以添加每个文件参数-w
。源更改,并且某些警告确实(或不)适用于不同的构建设置。clang 的消息可以告诉您什么标志等同于生成的警告。
To use Xcode to alter a file's build flags:
要使用 Xcode 更改文件的构建标志:
- select the target
- select the build phase
- locate the file to modify the arguments in the "Compile Sources" phase
- double click its "Compiler Flags" cell to edit
- 选择目标
- 选择构建阶段
- 在“编译源”阶段找到要修改参数的文件
- 双击其“编译器标志”单元格进行编辑
回答by kcharwood
I inherited a project that contained a lot of 320 code, and that code base threw several warnings and static analyzer errors at me that I had no interest in fixing since I will be removing that code from the project in the near future.
我继承了一个包含大量 320 代码的项目,该代码库向我抛出了几个警告和静态分析器错误,我没有兴趣修复这些错误,因为我将在不久的将来从项目中删除该代码。
You can disable static analyzer warnings for a specific file by including the following compiler flag:
您可以通过包含以下编译器标志来禁用特定文件的静态分析器警告:
-Xanalyzer -analyzer-disable-all-checks
You can combine this with -w to disable warnings for that file as well. That has allowed me to push forward with new development while not having to be pestered with the 30 or so warnings generated by that code base.
您也可以将其与 -w 结合使用以禁用该文件的警告。这使我能够推进新的开发,而不必被该代码库生成的 30 个左右的警告所困扰。
Using the instructions from above: To use Xcode to alter a file's build flags:
使用上面的说明:要使用 Xcode 更改文件的构建标志:
- select the target
- select the build phase
- locate the file to modify the arguments in the "Compile Sources" phase
- double click its "Compiler Flags" cell to edit
- add "-w -Xanalyzer -analyzer-disable-all-checks" to suppress warnings and clang warnings
- 选择目标
- 选择构建阶段
- 在“编译源”阶段找到要修改参数的文件
- 双击其“编译器标志”单元格进行编辑
- 添加“-w -Xanalyzer -analyzer-disable-all-checks”以抑制警告和叮当声警告
回答by Robert
With the help of justin's answer, this is how you do
在贾斯汀的回答的帮助下,这就是你的方式
1. Locate the name of the warning.
1. 找到警告的名称。
In my case its conversion
在我的情况下 conversion
2. Add a per file compiler flag build phases
2. 添加每个文件编译器标志构建阶段
Use the filter to find the name of the file in compile sources, type -Wno-[error name]
e.g. -Wno-conversion
使用过滤器在编译源中查找文件名,输入-Wno-[error name]
eg-Wno-conversion
回答by dormitkon
You can select specific target -> Build settings, search for Inhibit All Warnings and set to YES. This will disable warnings on this target. This can be useful if you use some code like JSONKit with cocoapods, and you don't want to see how compiler cries about warnings :)
您可以选择特定目标 -> 构建设置,搜索 Inhibit All Warnings 并设置为 YES。这将禁用此目标上的警告。如果您将 JSONKit 之类的代码与 cocoapods 一起使用,并且您不想看到编译器如何对警告发出警告,这会很有用 :)