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