Consider the following files, test.h and test.m: test.h: ------- /* Contributed by Nicola Pero - Tue Jan 16 04:09:06 GMT 2007 */ #include <objc/objc.h> #include <objc/Object.h> @interface TestClass : Object + (int) test; @end test.m: ------- #include "test.h" @implementation TestClass + (int) test { return 0; } @end int main (void) { return [TestClass test]; } My compiler is 4.1.1 20070105 (Red Hat 4.1.1-51). If I compile the files in the standard way -- gcc test.m -lobjc it all works. If I first precompile test.h gcc -x objective-c-header test.h I get the test.h.gch file, which looks ok, but then compiling fails -- gcc test.m -lobjc test.m:4: warning: cannot find interface declaration for �TestClass� test.m:4: error: redefinition of �struct TestClass� (compilation aborts) (I also got a compiler internal error once) Using the -H option to gcc you can indeed confirm that compilation fails iff the precompiled ObjC header is used. It seems that ObjC class declarations in ObjC headers are not read correctly/at all from precompiled headers (C stuff works fine instead!). Very disappointing. :-( I hope I'm missing an option / something, else it's a bug that needs fixing :-( Thanks
Created attachment 12908 [details] test case (header)
Created attachment 12909 [details] test case (ObjC file)
Confirmed, a regression from 4.0.4 where this worked. I will look into this more soon.
Once fixed, it might be worthwhile adding testcases for this then ? :-) Thanks
(In reply to comment #4) > Once fixed, it might be worthwhile adding testcases for this then ? :-) Yes and I am going to try to do that also.
Well this was caused by the objective-C++ merge. This is also a classic example of why hashing on pointer values is not a good idea. Working on a fix, should also simplify the code :).
I have a full fix and a semi working testsuite (semi working mean it will work for non remote testing). This is just a good example of when you should not use pointer hashing, especially when there is already a hash for identifiers.
Subject: Bug 30479 Author: pinskia Date: Sun Jan 21 06:51:07 2007 New Revision: 121024 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=121024 Log: 2007-01-20 Andrew Pinski <pinskia@gmail.com> PR objc/30479 * objc-act.c (hash_interface): Use IDENTIFIER_HASH_VALUE instead of htab_hash_pointer. (lookup_interface): Likewise. (add_class): Likewise. 2007-01-20 Andrew Pinski <pinskia@gmail.com> PR objc/30479 * objc.dg/pch: New directory. * objc.dg/pch/pch.exp: New file. * objc.dg/pch/interface-1.m: New test. * objc.dg/pch/interface-1.hs: New include file. * lib/objc.exp (objc_target_compile): Add "-x objective-c-header" in front of the sources if this is a precompiled header being compiled. Added: trunk/gcc/testsuite/objc.dg/pch/ trunk/gcc/testsuite/objc.dg/pch/interface-1.hs trunk/gcc/testsuite/objc.dg/pch/interface-1.m trunk/gcc/testsuite/objc.dg/pch/pch.exp Modified: trunk/gcc/objc/ChangeLog trunk/gcc/objc/objc-act.c trunk/gcc/testsuite/ChangeLog trunk/gcc/testsuite/lib/objc.exp
Subject: Bug 30479 Author: pinskia Date: Sun Jan 21 23:33:46 2007 New Revision: 121040 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=121040 Log: 2007-01-20 Andrew Pinski <pinskia@gmail.com> PR objc/30479 * objc-act.c (hash_interface): Use IDENTIFIER_HASH_VALUE instead of htab_hash_pointer. (lookup_interface): Likewise. (add_class): Likewise. 2007-01-20 Andrew Pinski <pinskia@gmail.com> PR objc/30479 * objc.dg/pch: New directory. * objc.dg/pch/pch.exp: New file. * objc.dg/pch/interface-1.m: New test. * objc.dg/pch/interface-1.hs: New include file. * lib/objc.exp (objc_target_compile): Add "-x objective-c-header" in front of the sources if this is a precompiled header being compiled. Added: branches/gcc-4_2-branch/gcc/testsuite/objc.dg/pch/ - copied from r121024, trunk/gcc/testsuite/objc.dg/pch/ Modified: branches/gcc-4_2-branch/gcc/objc/ChangeLog branches/gcc-4_2-branch/gcc/objc/objc-act.c branches/gcc-4_2-branch/gcc/testsuite/ChangeLog branches/gcc-4_2-branch/gcc/testsuite/lib/objc.exp
Testing on the 4.1 branch now.
Fixed in 4.1.2.
Subject: Bug 30479 Author: pinskia Date: Mon Jan 22 02:03:02 2007 New Revision: 121048 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=121048 Log: 2007-01-21 Andrew Pinski <pinskia@gmail.com> PR objc/30479 * objc-act.c (hash_interface): Use IDENTIFIER_HASH_VALUE instead of htab_hash_pointer. (lookup_interface): Likewise. (add_class): Likewise. 2007-01-21 Andrew Pinski <pinskia@gmail.com> PR objc/30479 * objc.dg/pch: New directory. * objc.dg/pch/pch.exp: New file. * objc.dg/pch/interface-1.m: New test. * objc.dg/pch/interface-1.hs: New include file. * lib/objc.exp (objc_target_compile): Add "-x objective-c-header" in front of the sources if this is a precompiled header being compiled. Added: branches/gcc-4_1-branch/gcc/testsuite/objc.dg/pch/ - copied from r121024, trunk/gcc/testsuite/objc.dg/pch/ Modified: branches/gcc-4_1-branch/gcc/objc/ChangeLog branches/gcc-4_1-branch/gcc/objc/objc-act.c branches/gcc-4_1-branch/gcc/testsuite/ChangeLog branches/gcc-4_1-branch/gcc/testsuite/lib/objc.exp