Clang和gcc选项可以抑制未定义的消息警告?

时间:2012-05-06 05:23:13

标签: objective-c macruby

clang和gcc是否可以选择禁止向对象发送未定义的消息?如果是这样,标志是什么?

使用clang 3.1:

test.mm:51:14: warning: instance method '-dfs_path:' not found (return type defaults to 'id')
            ([pathfinder dfs_path: graph, @[ NUM(start) ], NUM(goal), NUM(max_steps)])
            ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

使用gcc 4.2.1:

test.mm: In function ‘void test_path(objc_object*, objc_object*, int, int, int, BOOL)’:
test.mm:84: warning: no ‘-dfs_path:’ method found
test.mm:84: warning: (Messages without a matching method signature
test.mm:84: warning: will be assumed to return ‘id’ and accept
test.mm:84: warning: ‘...’ as arguments.)
test.mm:84: warning: no ‘-dfs_path:’ method found

基本上,有问题的方法是在MacRuby中生成的,因此Objective C编译器在编译时不知道它们。

2 个答案:

答案 0 :(得分:2)

我在Xcode中的clang的大部分警告都提供了有关在警告消息本身中解决该特定警告的信息。如果您手动运行clang(或者没有看到这些),则可以选择clang来打开此行为:

-f[no-]diagnostics-show-option

如果使用-fdiagnostics-show-option作为编译器选项,则应该会在警告中看到一个选项,例如:

foo.m:73:1: warning: category is implementing a method which will also be implemented by its
            primary class [-Wobjc-protocol-method-implementation]

这表示-Wobjc-protocol-method-implementation选项导致错误,添加-Wno-objc-protocol-method-implementation通常会将其禁用。

话虽如此,我建议不要关闭未定义方法的警告,方法定义将影响编译器处理返回值的方式,这可能会让你以后遇到很多麻烦。

如果没有合适的包含文件,则始终可以使用类别为方法声明本地定义。不是最干净的方式(包括声明),但有时是必要的。

@interface class_you_are_having_issues_with ()
- (id)dfs_path: (id)unknownarg, ...
@end

顺便说一下,我假设这是一种可变方法,因为那是你在Objective-C中使用逗号分隔的args的唯一时间。

希望这会指出你在两个方面的正确方向。

答案 1 :(得分:0)

尝试-Wno-objc-method-access - 在clang中为我工作。