Home | History | Annotate | Download | only in SemaObjC
      1 // RUN: %clang_cc1 -fsyntax-only -verify %s
      2 
      3 typedef struct objc_object {
      4   struct objc_class *isa;
      5 } *id;
      6 
      7 @interface NSObject {
      8   id firstobj;
      9   struct objc_class *isa;
     10 }
     11 @end
     12 @interface Whatever : NSObject
     13 +self;
     14 @end
     15 
     16 static void func() {
     17  
     18   id x;
     19 
     20   // rdar://8290002
     21   [(*x).isa self]; // expected-warning {{direct access to Objective-C's isa is deprecated in favor of object_setClass() and object_getClass()}}
     22   [x->isa self]; // expected-warning {{direct access to Objective-C's isa is deprecated in favor of object_setClass() and object_getClass()}}
     23   
     24   Whatever *y;
     25 
     26   // GCC allows this, with the following warning: 
     27   //   instance variable 'isa' is @protected; this will be a hard error in the future
     28   //
     29   // FIXME: see if we can avoid the warning that follows the error.
     30   [(*y).isa self]; // expected-error {{instance variable 'isa' is protected}} \
     31                       expected-warning{{receiver type 'struct objc_class *' is not 'id' or interface pointer, consider casting it to 'id'}}
     32   [y->isa self]; // expected-error {{instance variable 'isa' is protected}} \
     33                     expected-warning{{receiver type 'struct objc_class *' is not 'id' or interface pointer, consider casting it to 'id'}}
     34 }
     35 
     36 // rdar://11702488
     37 // If an ivar is (1) the first ivar in a root class and (2) named `isa`,
     38 // then it should get the same warnings that id->isa gets.
     39 
     40 @interface BaseClass {
     41 @public
     42     Class isa; // expected-note 3 {{instance variable is declared here}}
     43 }
     44 @end
     45 
     46 @interface OtherClass {
     47 @public
     48     id    firstIvar;
     49     Class isa; // note, not first ivar;
     50 }
     51 @end
     52 
     53 @interface Subclass : BaseClass @end
     54 
     55 @interface SiblingClass : BaseClass @end
     56 
     57 @interface Root @end
     58 
     59 @interface hasIsa : Root {
     60 @public
     61   Class isa; // note, isa is not in root class
     62 }
     63 @end
     64 
     65 @implementation Subclass
     66 -(void)method {
     67     hasIsa *u;
     68     id v;
     69     BaseClass *w;
     70     Subclass *x;
     71     SiblingClass *y;
     72     OtherClass *z;
     73     (void)v->isa; // expected-warning {{direct access to Objective-C's isa is deprecated}}
     74     (void)w->isa; // expected-warning {{direct access to Objective-C's isa is deprecated}}
     75     (void)x->isa; // expected-warning {{direct access to Objective-C's isa is deprecated}}
     76     (void)y->isa; // expected-warning {{direct access to Objective-C's isa is deprecated}}
     77     (void)z->isa;
     78     (void)u->isa;
     79 }
     80 @end
     81 
     82