This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: PATCH: Selector warning

> That's what I did initially, but all methods are not required to
> be declared in @interfaces. For example, we do not want to warn
> about 'foobar'

Why not ?  Definitely yes instead - we *do* want to warn about it.  :-)

It would be consistent with what happens with method calls - in your
example, if you do 

Foo *myObject = [Foo new];

[myObject foobar];

where you have now put the @selector(foobar), you *do* get a warning that
foobar is not implemented by Foo(instance), because it's true that the
selector/method will exist at runtime, but you have not let the compiler
know by declaring it in an interface before using it.

You can make the warning go away by adding

@interface Foo (Private)
- (void) foobar;

before the method call; or by implementing -foobar before you reference it
(that is, moving -foobar up one method in your example).  This is standard

I would expect exactly *the same* to happen for @selector().  The selector
has to be declared in an interface before it's used.  If not, and if you
explicitly ask for selector warnings with -Wselector, you get the warning.  
That is just exactly as it should be. :-)

Consistency with what the compiler does in other perfectly similar
situations, plus the fact that you get the warning as soon as the compiler
hits the line and not only at the end of compilation and only if you
actually reach item, are IMO definite points in favour of checking for the
selector when it's actually found, and not at the end of compilation.

> typedef struct objc_object { struct objc_class *class_pointer; } *id;
> typedef struct objc_selector    *SEL;
> @interface Foo
> - (void) foo;
> - (void) bar;
> @end
> @implementation Foo
> - (void) bar
> {
> }
> - (void) foo
> {
>    SEL a,b,c;
>    a = @selector(b1ar);
>    b = @selector(bar);
>    c = @selector(foobar);
> }
> - (void) foobar
> {
> }
> @end
> -Devang

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]