[PATCH] fix Objective-C, further improve error recovery for unknown type names

Nicola Pero nicola.pero@meta-innovation.com
Sat Nov 13 23:19:00 GMT 2010


>> I accepted to deviate a bit from this good rule for "for" loops,  
>> since Objective-C is not a superset of C there:
>>
>> int f()
>> {
>>        for (int in = 0; ; )
>>                ;
>> }
>>
>> gives
>>
>> f.c:3:11: error: expected identifier or ‘(’ before ‘in’
>>
>> in Objective-C.  I think foreach syntax is a very bad idea, though  
>> not your fault of course.  "for (x : a)" would have been much better.
>
> This probably reflects that we've still some bugs to shake out of the  
> (new) implementation.
> on Darwin, both "gcc-4.2 -x objective-c" and "clang -ObjC  "
>
> warn (a) about the c99 requirement and (b) that the var "in" is unused.
> (which seems like the correct behavior)

You may want to try a more interesting case --

 int in = 0;

 for (in = in + 1; in < 10; in++)
   printf ("%d\n", in);

try it in C and Objective-C.  Do you get the same result ?

In our implementation, I took the approach of simply not allowing 'in' as a variable 
in a 'for' loop in Objective-C.  That may be simplistic and we may want to be more
sophisticated; but if we follow a more complicated logic, we need to document it clearly.
It is ugly to have some hidden heuristics inside the compiler arbitrarily decide what
'in' means, as users have no way of knowing when 'in' can be used as a variable and 
when it can not. ;-)

Thanks



More information about the Gcc-patches mailing list