http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48527
Summary: Incorrect list of methods in @protocol used across compilation units Product: gcc Version: 4.6.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: objc AssignedTo: unassig...@gcc.gnu.org ReportedBy: nic...@gcc.gnu.org I'm using GCC 4.6.0. The following example shows things working correctly when a protocol is used in the same compilation unit: [nicola@lampone ~]$ cat x1.m #include <objc/runtime.h> @protocol A - (void) test; @end int main (void) { Protocol *p = @protocol (A); struct objc_method_description method = protocol_getMethodDescription (p, @selector (test), YES, YES); printf ("Protocol name is %s\n", protocol_getName (p)); printf ("Method is %s, %s\n", sel_getName (method.name), method.types); return 0; } [nicola@lampone ~]$ gcc x1.m -lobjc x1.m: In function ‘main’: x1.m:13:3: warning: incompatible implicit declaration of built-in function ‘printf’ [enabled by default] [nicola@lampone ~]$ ./a.out Protocol name is A Method is test, v8@0:4 [nicola@lampone ~]$ This shows the protocol being recognized, and the full list of methods being available when you introspect the protocol. :-) But, if you move the @protocol to another compilation unit, things stop working! :-( [nicola@lampone ~]$ cat x2.m #include <objc/runtime.h> @protocol A; int main (void) { Protocol *p = @protocol (A); struct objc_method_description method = protocol_getMethodDescription (p, @selector (test), YES, YES); printf ("Protocol name is %s\n", protocol_getName (p)); printf ("Method is %s, %s\n", sel_getName (method.name), method.types); return 0; } [nicola@lampone ~]$ gcc x2.m -c x2.m: In function ‘main’: x2.m:11:3: warning: incompatible implicit declaration of built-in function ‘printf’ [enabled by default] [nicola@lampone ~]$ cat x3.m #include <objc/runtime.h> @protocol A - (void) test; @end [nicola@lampone ~]$ gcc x3.m -c [nicola@lampone ~]$ gcc x2.o x3.o -lobjc [nicola@lampone ~]$ ./a.out Protocol name is A Method is <null selector>, (null) [nicola@lampone ~]$ As you can see, in this case the protocol looks good if you check only the name, but it isn't, since the method is not there in the list of protocol methods! Thanks