Clang(在 Xcode 中):从 -Weverything 开始并手动禁用特定警告

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16384530/
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 03:20:07  来源:igfitidea点击:

Clang (in Xcode): start with -Weverything and manually disable particular warnings

objective-cxcodeclang

提问by 7cows

I like to use -Weverythingfor the compiler to catch all possible warnings, but sometimes I get warnings that I don't want to fix. How can I manually disable those particular warnings as they occur?

我喜欢使用-Weverything编译器来捕获所有可能的警告,但有时我会收到不想修复的警告。如何在出现这些特定警告时手动禁用它们?

回答by

You can disable individual warnings using -Wno-XYZ, XYZ being the name of the warning feature to be disabled.

您可以使用 禁用单个警告-Wno-XYZ,XYZ 是要禁用的警告功能的名称。

回答by max

XCode

代码

In XCode 5 I had to build, then right click on an issue and select "Reveal in Log" then set the Middle Pane tab to "All" too get the issues displayed in the log.

在我必须构建的 XCode 5 中,然后右键单击一个问题并选择“在日志中显示”,然后将中间窗格选项卡设置为“全部”也让问题显示在日志中。

Then clicking on the "Hamburger" Icon to the right and scrolling down I finally got an exact description of the Warning.

然后单击右侧的“汉堡包”图标并向下滚动,我终于得到了警告的确切描述。

/.../SettingsViewController.m:91:58: warning: creating selector for nonexistent method 'setSegueIdentifier:' [-Wselector]
    [segue.destinationViewController performSelector:@selector(setSegueIdentifier:)

So in my case the following does the job.

因此,在我的情况下,以下内容可以完成工作。

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wselector"
...
#pragma clang diagnostic pop

回答by Ohad Schneider

I just bumped into a site that lists all Clang warnings and the flags that disable them (using #pragma clang diagnostic ignored "-Wxyz"):

我刚碰到一个网站,该网站列出了所有 Clang 警告和禁用它们的标志(使用#pragma clang diagnostic ignored "-Wxyz"):

http://goo.gl/hwwIUa(when you visit it you'll understand why I've shortened the URL).

http://goo.gl/hwwIUa(当您访问它时,您就会明白为什么我缩短了 URL)。

回答by GayleDDS

I'm guessing you know how to update the build settings to enable/disable individual warnings and want to disable the warning in your code. Here is an example:

我猜您知道如何更新构建设置以启用/禁用单个警告并希望禁用代码中的警告。下面是一个例子:

#ifdef TESTFLIGHT_USERTRACKING

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
#pragma clang diagnostic ignored "-Wdeprecated-implementations"

[TestFlight setDeviceIdentifier:[[UIDevice currentDevice] uniqueIdentifier]];

#pragma clang diagnostic pop

#endif