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