[cfe-dev] Stricter ObjC warning 'class' may not respond to 'selector'

Volodymyr Sapsai vsapsai at gmail.com
Wed Sep 14 16:12:53 PDT 2011


Hi,
currently clang compiles following code with a warning "'FooClass' may
not respond to 'barMethod'"

//foo.h
#import <Foundation/NSObject.h>
@interface FooClass : NSObject {
}
- (void)fooMethod;
@end

//bar.h
#import <Foundation/NSObject.h>
@interface BarClass : NSObject{
}
- (void)barMethod;
@end

//handleFoo.m
#import "bar.h"
#import "foo.h"

void handleFoo(FooClass *foo) {
	[foo barMethod];
}

But if instead of #import "foo.h" we forward declare FooClass, i.e.
#import "bar.h"
@class FooClass;

void handleFoo(FooClass *foo) {
	[foo barMethod];
}

then there is no warning.

By currently I mean Apple clang version 2.0 (tags/Apple/clang-139)
(based on LLVM 2.9svn) and clang built from r139743.

I think it would be useful to emit warning in case of forward
declaration. What do you think?

Regards,
Volodymyr Sapsai




More information about the cfe-dev mailing list