[cfe-dev] Name lookup in ObjC methods

Argiris Kirtzidis akyrtzi at gmail.com
Fri Mar 21 04:53:14 PDT 2008

Chris Lattner wrote:
>>> int foo::test2(q r) {
>>>   return X+r;
>>> }
>> This is actually quite tricky, because clang currently assumes that a
>> declaration can be "found"
>> only by using an identifier (support for '::' in "foo::test2" needed),
>> and for name lookup it
>> assumes that the declaration is accessible at the current scope or  
>> at an
>> enclosing scope of the
>> current one (support for resolving X in "return X+r;" needed).
> It's not that bad, we already handle it for instance variables in ObjC.
Actually, name lookup in ObjC methods is not working correctly. For example:

@interface Test {
    int x;

-(void) setX: (int) d;

char *x;

@implementation Test

-(void) setX: (int) n {
    x = n;


If you compile it with "clang test.m -fsyntax-only -pedantic-errors" 
you'll get:

main.m:13:7: error: incompatible integer to pointer conversion assigning 
'int', expected 'char *'
    x = n;
      ^ ~

I'm not familiar with Objective C, but isn't it supposed to pick up the 
'x' instance variable instead of the global one ?

More information about the cfe-dev mailing list