什么是“实例方法未找到”警告的-Wsomething标志? [英] What's the -Wsomething flag for 'instance method not found' warnings?

查看:308
本文介绍了什么是“实例方法未找到”警告的-Wsomething标志?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近遇到了一个情况,有人向init方法添加了一个参数,并打破了另一个共享代码的项目。因为它只是一个警告,没有人意识到应用程序被打破,所以我试图把这个警告变成一个错误:

I recently had a case where someone added a parameter to an init method and broke another project that shared the code. Since it's only a warning, nobody realized the app was broken, so I'm trying to turn only this warning into an error:

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

我发现你可以传递-Werror = foo在其他C标志到编译器在Xcode中的警告错误,但我似乎找不到什么'foo'应该是。我试过'undeclared选择器,但只有捕获@selector情况。我尝试了-Werror-implicit-function-declaration,但似乎没有捕获到这种情况。

I've found that you can pass -Werror=foo in Other C Flags to the compiler in Xcode to turn a warning into the error, but I can't seem to find what 'foo' should be. I've tried 'undeclared-selectors' but that only catches @selector cases. I've tried -Werror-implicit-function-declaration but that doesn't seem to catch that case either.

我尝试了inst-method-not-found

I tried 'inst-method-not-found' and 'instance-method-not-found' after finding 'warn_inst_method_not_found' during a casual search of the huge clang source code.

帮助...?

更新:
下面是一个例子,你可以编译(例如在CodeRunner中)看到警告: https://gist.github.com/4045701

推荐答案

选项你正在寻找 -Werror = objc-method-access 。 Clang在警告消息中明确告诉你这个权限,如果你下载并编译了你发布的gist:

The option you're looking for is -Werror=objc-method-access. Clang explicitly tells you this right in the warning message, if you download and compile that gist you posted:

% 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!

但在现实世界的情况下,我同意上面所有的评论者:你应该解决或取消 all 编译器警告。你的构建应该干净地建立全部时间。否则,正如你正确地观察到的,你将无法区分真正的bug和通常的垃圾邮件。

But in real-world situations I agree with all the commenters above: You should fix or suppress all compiler warnings. Your build should build cleanly all the time. Otherwise, as you so rightly observed, you won't be able to distinguish real bugs from "the usual spam".

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

FWIW, here's the version of Clang I'm using:

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

这篇关于什么是“实例方法未找到”警告的-Wsomething标志?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆