discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Objective-C bug?


From: Jonathan Olson
Subject: Objective-C bug?
Date: Thu, 3 Jun 2004 22:27:17 -0700

The gcc 3.3.3 Objective-C compiler on Linux generates bogus method name conflicts which do not occur on the gcc 3.3 compiler on OSX. Objective-C should be able to distinguish between identically named class methods in the following example.

For example, the following program compiles cleanly on OSX Panther/gcc 3.3, but generates error messages on gcc 3.3.3 on Linux. I realize that this particular example could be fixed by changing the return type of both create methods to (id), but other examples are not as easy to fix. For example the method "protocol" gets defined in NSProtocolChecker as returning type (Protocol *), making it impossible to use a class method "protocol" in any other class.

#include <Foundation/Foundation.h>

@interface Foo : NSObject
+ (Foo *)create;
- (NSString *)description;
@end

@interface Baz : NSObject
+ (Baz *)create;
- (NSString *)description;
@end

@implementation Foo
+ (Foo *)create {
return [[[Foo alloc] init] autorelease];
}
- (NSString *)description {
return @"Foo";
}
@end

@implementation Baz
+ (Baz *)create {
return [[[Baz alloc] init] autorelease];
}
- (NSString *)description {
return @"Baz";
}
@end

int
main(void)
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
Foo *foo = [Foo create];
Baz *baz = [Baz create];
NSLog(@"foo:%@\n", foo);
NSLog(@"baz:%@\n", baz);
[pool release];
return 0;
}

On Linux gcc 3.3.3, this example generates the following warnings:

Baz.m: In function `main':
Baz.m:35: warning: multiple declarations for method `create'
Baz.m:4: warning: using `+(Foo *)create'
Baz.m:23: warning: also found `+(Baz *)create'
Baz.m:9: warning: also found `+(Baz *)create'
Baz.m:36: warning: multiple declarations for method `create'
Baz.m:4: warning: using `+(Foo *)create'
Baz.m:23: warning: also found `+(Baz *)create'
Baz.m:9: warning: also found `+(Baz *)create'
Baz.m:36: warning: initialization from incompatible pointer type

reply via email to

[Prev in Thread] Current Thread [Next in Thread]