Home | History | Annotate | Download | only in SemaObjCXX
      1 // RUN: %clang_cc1 -fblocks -fobjc-arc -fobjc-runtime-has-weak %s -verify
      2 
      3 // rdar://21612439
      4 
      5 __attribute__((objc_root_class))
      6 @interface NSObject
      7 @end
      8   
      9 @class Forward;
     10 @class Forward2;
     11 
     12 // Tests for generic arguments.
     13 
     14 @interface PC1<T> : NSObject
     15 - (T) get;
     16 - (void) set: (T) v;
     17 @end
     18 
     19 void test1a(PC1<__weak id> *obj) { // expected-error {{type argument '__weak id' cannot be qualified with '__weak'}}
     20   id x = [obj get];
     21   [obj set: x];
     22 }
     23 
     24 void test1b(PC1<__strong id> *obj) { // expected-error {{type argument '__strong id' cannot be qualified with '__strong'}}
     25   id x = [obj get];
     26   [obj set: x];
     27 }
     28 
     29 void test1c(PC1<id> *obj) {
     30   id x = [obj get];
     31   [obj set: x];
     32 }
     33 
     34 // Test that this doesn't completely kill downstream type-checking.
     35 void test1d(PC1<__weak Forward*> *obj) { // expected-error {{type argument 'Forward *__weak' cannot be qualified with '__weak'}}
     36   Forward2 *x = [obj get]; // expected-error {{cannot initialize}}
     37   [obj set: x];
     38 }
     39 
     40 void test1e(PC1<__strong Forward*> *obj) { // expected-error {{type argument 'Forward *__strong' cannot be qualified with '__strong'}}
     41   Forward2 *x = [obj get]; // expected-error {{cannot initialize}}
     42   [obj set: x];
     43 }
     44 
     45 void test1f(PC1<Forward*> *obj) {
     46   Forward2 *x = [obj get]; // expected-error {{cannot initialize}}
     47   [obj set: x];
     48 }
     49 
     50 // Typedefs are fine, just silently ignore them.
     51 typedef __strong id StrongID;
     52 void test1g(PC1<StrongID> *obj) {
     53   Forward2 *x = [obj get];
     54   [obj set: x];
     55 }
     56 
     57 typedef __strong Forward *StrongForward;
     58 void test1h(PC1<StrongForward> *obj) {
     59   Forward2 *x = [obj get]; // expected-error {{cannot initialize}}
     60   [obj set: x];
     61 }
     62 
     63 // These aren't really ARC-specific, but they're the same basic idea.
     64 void test1i(PC1<const id> *obj) { // expected-error {{type argument 'const id' cannot be qualified with 'const'}}
     65   id x = [obj get];
     66   [obj set: x];
     67 }
     68 
     69 void test1j(PC1<volatile id> *obj) { // expected-error {{type argument 'volatile id' cannot be qualified with 'volatile'}}
     70   id x = [obj get];
     71   [obj set: x];
     72 }
     73 
     74 void test1k(PC1<__attribute__((address_space(256))) id> *obj) { // expected-error {{type argument '__attribute__((address_space(256))) id' cannot be qualified with '__attribute__((address_space(256)))'}}
     75   id x = [obj get];
     76   [obj set: x];
     77 }
     78 
     79 // Template-specific tests.
     80 template <class T> PC1<T> *test2_temp();
     81 void test2a() { test2_temp<id>(); }
     82 void test2b() { test2_temp<const id>(); }
     83 void test2c() { test2_temp<volatile id>(); }
     84 void test2d() { test2_temp<__strong id>(); }
     85 void test2e() { test2_temp<__weak id>(); }
     86 void test2f() { test2_temp<__attribute__((address_space(256))) id>(); }
     87 
     88 template <class T> PC1<const T> *test3a(); // expected-error {{type argument 'const T' cannot be qualified with 'const'}}
     89 template <class T> PC1<__strong T> *test3b(); // expected-error {{type argument '__strong T' cannot be qualified with '__strong'}}
     90 
     91 // Tests for generic parameter bounds.
     92 
     93 @interface PC2<T : __strong id> // expected-error {{type bound '__strong id' for type parameter 'T' cannot be qualified with '__strong'}}
     94 @end
     95 
     96 @interface PC3<T : __weak id> // expected-error {{type bound '__weak id' for type parameter 'T' cannot be qualified with '__weak'}}
     97 @end
     98 
     99 @interface PC4<T : __strong Forward*> // expected-error {{type bound 'Forward *__strong' for type parameter 'T' cannot be qualified with '__strong'}}
    100 @end
    101 
    102 @interface PC5<T : __weak Forward*> // expected-error {{type bound 'Forward *__weak' for type parameter 'T' cannot be qualified with '__weak'}}
    103 @end
    104 
    105 @interface PC6<T : StrongID> // expected-error {{type bound 'StrongID' (aka '__strong id') for type parameter 'T' cannot be qualified with '__strong'}}
    106 @end
    107 
    108 @interface PC7<T : StrongForward> // expected-error {{type bound 'StrongForward' (aka 'Forward *__strong') for type parameter 'T' cannot be qualified with '__strong'}}
    109 @end
    110 
    111 // These aren't really ARC-specific, but they're the same basic idea.
    112 @interface PC8<T : const id> // expected-error {{type bound 'const id' for type parameter 'T' cannot be qualified with 'const'}}
    113 @end
    114 
    115 @interface PC9<T : volatile id> // expected-error {{type bound 'volatile id' for type parameter 'T' cannot be qualified with 'volatile'}}
    116 @end
    117 
    118 @interface PC10<T : __attribute__((address_space(256))) id> // expected-error {{type bound '__attribute__((address_space(256))) id' for type parameter 'T' cannot be qualified with '__attribute__((address_space(256)))'}}
    119 @end
    120