KushalP/ocmock — comment on commit f7cfaa2daca621f9a049a4548294f907070bafd9
File:  line 0
By nico:

It looks like this is a clang bug of sorts

$ cat test.mm
#import

void f() {
Protocol* p;
[NSString stringWithFormat:@"%s", [p name]];
}
$ third_party/llvm-build/Release+Asserts/bin/clang -c test.mm
test.mm:5:33: warning: format specifies type 'char *' but the argument has type 'NSString *' [-Wformat]
[NSString stringWithFormat:@"%s", [p name]];
~^ ~~~~~~~~
1 warning generated.

What's happening is that Protocol is only forward-declared, and several other classes declare a `(NSString*)name` function. So the only `-name` function clang knows about returns `NSString`, hence the warning. Ideally, clang's warning would be less misleading.

Adding a `#include ` makes the warning goes away when building with `-isysroot /Developer/SDKs/MacOSX10.5.sdk`, so that's the right fix. (With the 10.6 SDK, you'll get:

test.mm:7:38: error: 'name' is unavailable
[NSString stringWithFormat:@"%s", [p name]];
^
/usr/include/objc/Protocol.h:46:1: note: declaration has been explicitly marked unavailable here
- (const char *)name OBJC2_UNAVAILABLE;
^
1 error generated.

But that's a good thing.)