objective-c - 'instance method not found' 警告的 -Wsomething 标志是什么?

标签 objective-c cocoa warnings clang

我最近遇到一个案例,有人在 init 方法中添加了一个参数,并破坏了另一个共享代码的项目。由于这只是一个警告,没有人意识到该应用程序已损坏,所以我试图将此警告变成错误:

warning: instance method '-someMethod' not found (return type defaults to 'id')

我发现您可以将其他 cflags中的 -Werror=foo 传递给 Xcode 中的编译器以将警告转换为错误,但我似乎无法找到“foo”应该是什么。我试过“未声明的选择器”,但它只捕获@selector 的情况。我试过 -Werror-implicit-function-declaration 但这似乎也没有捕获这种情况。

在随意搜索巨大的 clang 源代码期间找到“warn_inst_method_not_found”后,我尝试了“inst-method-not-found”和“instance-method-not-found”。

帮助...?

更新: 这是一个您可以编译(例如在 CodeRunner 中)以查看警告的示例:https://gist.github.com/4045701

最佳答案

您正在寻找的选项是 -Werror=objc-method-access。如果您下载并编译您发布的要点,Clang 会在警告消息中明确告诉您这一点:

% clang test.m -c
test.m:13:21: warning: instance method '-initWithNum:' not found (return type
      defaults to 'id') [-Wobjc-method-access]
  ...theObj = [[MyClass alloc] initWithNum: [NSNumber numberWithInt: 15]];
              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 warning generated.

% clang test.m -Werror=objc-method-access -c  // ta-da!

但在现实世界中,我同意以上所有评论者的观点:您应该修复或抑制所有 编译器警告。您的构建应该始终 干净地构建。否则,正如您正确观察到的那样,您将无法将真正的错误与“常见的垃圾邮件”区分开来。

FWIW,这是我使用的 Clang 版本:

$ clang --version
clang version 3.2  (http://llvm.org/git/llvm 1503aba4a036f5394c7983417bc1e64613b2fc77)
Target: x86_64-apple-darwin12.2.0
Thread model: posix

关于objective-c - 'instance method not found' 警告的 -Wsomething 标志是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13308322/

相关文章:

objective-c - - (id)copyWithZone :(NSZone *)zone - memory leaks

c++ - 从长远来看,最好的方法是什么 : C, Objective C 或 C++?

iphone - 在 objective-c 中绘制 iPhone

objective-c - NSString writeToFile 的问题

cocoa - NSMetadataQuery 找不到 Lion、Mountain Lion 或 Mavericks 中的文件

ios - 关于隐式转换丢失整数精度的警告

iphone - 触摸开始驳回 View

cocoa - 如何将 NSAttributedString 中的字符大小写更改为大写

python - 如何确定地抑制 Python 中的 DeprecationWarning?

java - 如何抑制 m2e 警告?