I expect the following code to produce warnings about implicit declaration of functions:
@interface TestClass : NSObject
@end
@implementation TestClass
- (void)foo {
NSString *test = [self bar];
NSLog(@"%@", test);
test = baz();
NSLog(@"%@", test);
}
- (NSString *)bar {
return @"bar";
}
NSString *baz() {
return @"baz";
}
@end
Specifically I would expect warnings about using both bar
and baz
before they are declared. (bar
would be assumed to return id
and baz
would be assumed to return int
.)
GCC shows both warnings, as does LLVM's Clang 2.9. Clang 3, however, can apparently figure out that bar
and baz
exist and what they return. No warning appears (unless the functions are removed).
(When baz
is declared outside of the class, the warning still occurs. So this only applies to Objective-C!)
Awesome! That would allow a lot of duplication to be removed. But what is going on? Is this a language extension? Is it a compiler feature? Is it a bug? Or am I mistaken about this? I couldn't find any documentation on this, so I am wary of relying on it. Does anybody have any insight?