FYI: You may want to use -Wstrict-selector-match
FYI: You may want to use -Wstrict-selector-match
- Subject: FYI: You may want to use -Wstrict-selector-match
- From: Ricky Sharp <email@hidden>
- Date: Tue, 21 Jun 2005 18:48:26 -0500
A while back I wrote about the problems I was having when compiling
my app against the 10.4U SDK using Xcode 2.1 (and gcc4.0).
I was able to track it down to a collision between a 'currentValue'
method provided by one of my NSControl subclasses and the
'currentValue' method provided by the new NSAnimation class.
I just got back a reply from DTS about the reason for this collision
and why the compiler didn't warn me.
NSAnimation's method is defined as:
- (float)currentValue;
My method was definited as:
- (int)currentValue;
In one of my control's setters, this was done:
- (void)setCurrentValue:(int)newCurrentValue
{
[[self cell] setCurrentValue:newCurrentValue];
}
But [self cell] returns id. The compiler had to then figure out
which currentValue to send to the object. By default, my Xcode
project didn't have the 'strict selector match' warning turned on
when using gcc4.0. This is why things happily compiled. Yet behind
the scenes, the compiler was choosing the currentValue method that
returned the float (probably because it found that one first when
including Cocoa.h).
Anyhow, when I added -Wstrict-selector-match to the 'Other C Flags'
of the project's build properties, I then got this warning output:
warning: multiple methods named '-currentValue' found
warning: using '-(float)currentValue'
warning: also found '-(int)currentValue'
One fix would be to cast the return value of [self cell] to the
appropriate object. In my case, (IIValueFieldCell*).
However, I took on a more aggressive fix and I just renamed my ivars,
accessors, etc. to all use a unique suffix (e.g. currentValue_II).
This way, I'll never collide with anything Apple adds.
So, if you're using the new gcc4.0 compiler, you may want to turn on
this warning and see if the compiler is generating the correct code
(i.e. using the methods you think it should be using).
FWIW, I believe this warning is on by default when using gcc3.3.
I've definitely received those warnings before when doing project
work with Xcode 1.5 running under 10.3.x.
___________________________________________________________
Ricky A. Sharp mailto:email@hidden
Instant Interactive(tm) http://www.instantinteractive.com
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden