objective-cmacruby

Clang and gcc options to suppress undefined messages warnings?


Do clang and gcc have an option to suppress warnings about sending an undefined message to an object? If so, what are the flags?

With 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)])
            ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

With 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

Basically, the methods in question are generated in MacRuby, and thus the Objective C compiler doesn't know about them at compile time.


Solution

  • Most of my warnings from clang in Xcode come out with the information about addressing that particular warning in the warning message itself. If you are manually running clang (or otherwise aren't seeing these), there's an option to clang that turns this behavior on:

    -f[no-]diagnostics-show-option
    

    If you use -fdiagnostics-show-option as a compiler option, then you should see an option listed in the warning, such as:

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

    This indicates that the -Wobjc-protocol-method-implementation option is causing the error, and that adding -Wno-objc-protocol-method-implementation will generally disable it.

    With that said, I would recommend against turning off the warning for undefined methods, the method definition will affect how the compiler handles return values and that can head off a lot of headaches for you later.

    If you don't have an appropriate include file, you can always declare a local definition for the method by using a category. Not the cleanest way (which would be including the declarations), but sometimes necessary.

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

    As an aside, I'm assuming that's a variadic method, since that's about the only time that you use comma-separated args in Objective-C.

    Hopefully this will point you in the right direction on both fronts.