• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// RUN: %clang_cc1 -fsyntax-only -fobjc-arc -fobjc-runtime-has-weak -verify -std=c++11 %s
2// expected-no-diagnostics
3
4// Check the results of the various type-trait query functions on
5// lifetime-qualified types in ARC.
6
7#define JOIN3(X,Y) X ## Y
8#define JOIN2(X,Y) JOIN3(X,Y)
9#define JOIN(X,Y) JOIN2(X,Y)
10
11#define TRAIT_IS_TRUE(Trait, Type) char JOIN2(Trait,__LINE__)[Trait(Type)? 1 : -1]
12#define TRAIT_IS_FALSE(Trait, Type) char JOIN2(Trait,__LINE__)[Trait(Type)? -1 : 1]
13#define TRAIT_IS_TRUE_2(Trait, Type1, Type2) char JOIN2(Trait,__LINE__)[Trait(Type1, Type2)? 1 : -1]
14#define TRAIT_IS_FALSE_2(Trait, Type1, Type2) char JOIN2(Trait,__LINE__)[Trait(Type1, Type2)? -1 : 1]
15
16struct HasStrong { id obj; };
17struct HasWeak { __weak id obj; };
18struct HasUnsafeUnretained { __unsafe_unretained id obj; };
19
20// __has_nothrow_assign
21TRAIT_IS_TRUE(__has_nothrow_assign, __strong id);
22TRAIT_IS_TRUE(__has_nothrow_assign, __weak id);
23TRAIT_IS_TRUE(__has_nothrow_assign, __autoreleasing id);
24TRAIT_IS_TRUE(__has_nothrow_assign, __unsafe_unretained id);
25TRAIT_IS_TRUE(__has_nothrow_assign, HasStrong);
26TRAIT_IS_TRUE(__has_nothrow_assign, HasWeak);
27TRAIT_IS_TRUE(__has_nothrow_assign, HasUnsafeUnretained);
28
29// __has_nothrow_copy
30TRAIT_IS_TRUE(__has_nothrow_copy, __strong id);
31TRAIT_IS_TRUE(__has_nothrow_copy, __weak id);
32TRAIT_IS_TRUE(__has_nothrow_copy, __autoreleasing id);
33TRAIT_IS_TRUE(__has_nothrow_copy, __unsafe_unretained id);
34TRAIT_IS_TRUE(__has_nothrow_copy, HasStrong);
35TRAIT_IS_TRUE(__has_nothrow_copy, HasWeak);
36TRAIT_IS_TRUE(__has_nothrow_copy, HasUnsafeUnretained);
37
38// __has_nothrow_constructor
39TRAIT_IS_TRUE(__has_nothrow_constructor, __strong id);
40TRAIT_IS_TRUE(__has_nothrow_constructor, __weak id);
41TRAIT_IS_TRUE(__has_nothrow_constructor, __autoreleasing id);
42TRAIT_IS_TRUE(__has_nothrow_constructor, __unsafe_unretained id);
43TRAIT_IS_TRUE(__has_nothrow_constructor, HasStrong);
44TRAIT_IS_TRUE(__has_nothrow_constructor, HasWeak);
45TRAIT_IS_TRUE(__has_nothrow_constructor, HasUnsafeUnretained);
46
47// __has_trivial_assign
48TRAIT_IS_FALSE(__has_trivial_assign, __strong id);
49TRAIT_IS_FALSE(__has_trivial_assign, __weak id);
50TRAIT_IS_FALSE(__has_trivial_assign, __autoreleasing id);
51TRAIT_IS_TRUE(__has_trivial_assign, __unsafe_unretained id);
52TRAIT_IS_FALSE(__has_trivial_assign, HasStrong);
53TRAIT_IS_FALSE(__has_trivial_assign, HasWeak);
54TRAIT_IS_TRUE(__has_trivial_assign, HasUnsafeUnretained);
55
56// __has_trivial_copy
57TRAIT_IS_FALSE(__has_trivial_copy, __strong id);
58TRAIT_IS_FALSE(__has_trivial_copy, __weak id);
59TRAIT_IS_FALSE(__has_trivial_copy, __autoreleasing id);
60TRAIT_IS_TRUE(__has_trivial_copy, __unsafe_unretained id);
61TRAIT_IS_FALSE(__has_trivial_copy, HasStrong);
62TRAIT_IS_FALSE(__has_trivial_copy, HasWeak);
63TRAIT_IS_TRUE(__has_trivial_copy, HasUnsafeUnretained);
64
65// __has_trivial_constructor
66TRAIT_IS_FALSE(__has_trivial_constructor, __strong id);
67TRAIT_IS_FALSE(__has_trivial_constructor, __weak id);
68TRAIT_IS_FALSE(__has_trivial_constructor, __autoreleasing id);
69TRAIT_IS_TRUE(__has_trivial_constructor, __unsafe_unretained id);
70TRAIT_IS_FALSE(__has_trivial_constructor, HasStrong);
71TRAIT_IS_FALSE(__has_trivial_constructor, HasWeak);
72TRAIT_IS_TRUE(__has_trivial_constructor, HasUnsafeUnretained);
73
74// __has_trivial_destructor
75TRAIT_IS_FALSE(__has_trivial_destructor, __strong id);
76TRAIT_IS_FALSE(__has_trivial_destructor, __weak id);
77TRAIT_IS_TRUE(__has_trivial_destructor, __autoreleasing id);
78TRAIT_IS_TRUE(__has_trivial_destructor, __unsafe_unretained id);
79TRAIT_IS_FALSE(__has_trivial_destructor, HasStrong);
80TRAIT_IS_FALSE(__has_trivial_destructor, HasWeak);
81TRAIT_IS_TRUE(__has_trivial_destructor, HasUnsafeUnretained);
82
83// __is_literal
84TRAIT_IS_TRUE(__is_literal, __strong id);
85TRAIT_IS_TRUE(__is_literal, __weak id);
86TRAIT_IS_TRUE(__is_literal, __autoreleasing id);
87TRAIT_IS_TRUE(__is_literal, __unsafe_unretained id);
88
89// __is_literal_type
90TRAIT_IS_TRUE(__is_literal_type, __strong id);
91TRAIT_IS_TRUE(__is_literal_type, __weak id);
92TRAIT_IS_TRUE(__is_literal_type, __autoreleasing id);
93TRAIT_IS_TRUE(__is_literal_type, __unsafe_unretained id);
94
95// __is_pod
96TRAIT_IS_FALSE(__is_pod, __strong id);
97TRAIT_IS_FALSE(__is_pod, __weak id);
98TRAIT_IS_FALSE(__is_pod, __autoreleasing id);
99TRAIT_IS_TRUE(__is_pod, __unsafe_unretained id);
100TRAIT_IS_FALSE(__is_pod, HasStrong);
101TRAIT_IS_FALSE(__is_pod, HasWeak);
102TRAIT_IS_TRUE(__is_pod, HasUnsafeUnretained);
103
104// __is_trivial
105TRAIT_IS_FALSE(__is_trivial, __strong id);
106TRAIT_IS_FALSE(__is_trivial, __weak id);
107TRAIT_IS_FALSE(__is_trivial, __autoreleasing id);
108TRAIT_IS_TRUE(__is_trivial, __unsafe_unretained id);
109TRAIT_IS_FALSE(__is_trivial, HasStrong);
110TRAIT_IS_FALSE(__is_trivial, HasWeak);
111TRAIT_IS_TRUE(__is_trivial, HasUnsafeUnretained);
112
113// __is_scalar
114TRAIT_IS_FALSE(__is_scalar, __strong id);
115TRAIT_IS_FALSE(__is_scalar, __weak id);
116TRAIT_IS_FALSE(__is_scalar, __autoreleasing id);
117TRAIT_IS_TRUE(__is_scalar, __unsafe_unretained id);
118
119// __is_standard_layout
120TRAIT_IS_TRUE(__is_standard_layout, __strong id);
121TRAIT_IS_TRUE(__is_standard_layout, __weak id);
122TRAIT_IS_TRUE(__is_standard_layout, __autoreleasing id);
123TRAIT_IS_TRUE(__is_standard_layout, __unsafe_unretained id);
124
125// __is_trivally_assignable
126TRAIT_IS_FALSE_2(__is_trivially_assignable, __strong id&, __strong id);
127TRAIT_IS_FALSE_2(__is_trivially_assignable, __strong id&, __weak id);
128TRAIT_IS_FALSE_2(__is_trivially_assignable, __strong id&, __autoreleasing id);
129TRAIT_IS_FALSE_2(__is_trivially_assignable, __strong id&, __unsafe_unretained id);
130TRAIT_IS_FALSE_2(__is_trivially_assignable, __strong id&, __strong id&&);
131TRAIT_IS_FALSE_2(__is_trivially_assignable, __strong id&, __weak id&&);
132TRAIT_IS_FALSE_2(__is_trivially_assignable, __strong id&, __autoreleasing id&&);
133TRAIT_IS_FALSE_2(__is_trivially_assignable, __strong id&, __unsafe_unretained id&&);
134TRAIT_IS_FALSE_2(__is_trivially_assignable, __weak id&, __strong id);
135TRAIT_IS_FALSE_2(__is_trivially_assignable, __weak id&, __weak id);
136TRAIT_IS_FALSE_2(__is_trivially_assignable, __weak id&, __autoreleasing id);
137TRAIT_IS_FALSE_2(__is_trivially_assignable, __weak id&, __unsafe_unretained id);
138TRAIT_IS_FALSE_2(__is_trivially_assignable, __weak id&, __strong id&&);
139TRAIT_IS_FALSE_2(__is_trivially_assignable, __weak id&, __weak id&&);
140TRAIT_IS_FALSE_2(__is_trivially_assignable, __weak id&, __autoreleasing id&&);
141TRAIT_IS_FALSE_2(__is_trivially_assignable, __weak id&, __unsafe_unretained id&&);
142
143TRAIT_IS_FALSE_2(__is_trivially_assignable, __autoreleasing id&, __strong id);
144TRAIT_IS_FALSE_2(__is_trivially_assignable, __autoreleasing id&, __weak id);
145TRAIT_IS_FALSE_2(__is_trivially_assignable, __autoreleasing id&, __autoreleasing id);
146TRAIT_IS_FALSE_2(__is_trivially_assignable, __autoreleasing id&, __unsafe_unretained id);
147TRAIT_IS_FALSE_2(__is_trivially_assignable, __autoreleasing id&, __strong id&&);
148TRAIT_IS_FALSE_2(__is_trivially_assignable, __autoreleasing id&, __weak id&&);
149TRAIT_IS_FALSE_2(__is_trivially_assignable, __autoreleasing id&, __autoreleasing id&&);
150TRAIT_IS_FALSE_2(__is_trivially_assignable, __autoreleasing id&, __unsafe_unretained id&&);
151
152TRAIT_IS_TRUE_2(__is_trivially_assignable, __unsafe_unretained id&, __strong id);
153TRAIT_IS_TRUE_2(__is_trivially_assignable, __unsafe_unretained id&, __weak id);
154TRAIT_IS_TRUE_2(__is_trivially_assignable, __unsafe_unretained id&, __autoreleasing id);
155TRAIT_IS_TRUE_2(__is_trivially_assignable, __unsafe_unretained id&, __unsafe_unretained id);
156TRAIT_IS_TRUE_2(__is_trivially_assignable, __unsafe_unretained id&, __strong id&&);
157TRAIT_IS_TRUE_2(__is_trivially_assignable, __unsafe_unretained id&, __weak id&&);
158TRAIT_IS_TRUE_2(__is_trivially_assignable, __unsafe_unretained id&, __autoreleasing id&&);
159TRAIT_IS_TRUE_2(__is_trivially_assignable, __unsafe_unretained id&, __unsafe_unretained id&&);
160
161TRAIT_IS_FALSE_2(__is_trivially_assignable, HasStrong&, HasStrong);
162TRAIT_IS_FALSE_2(__is_trivially_assignable, HasStrong&, HasStrong&&);
163TRAIT_IS_FALSE_2(__is_trivially_assignable, HasWeak&, HasWeak);
164TRAIT_IS_FALSE_2(__is_trivially_assignable, HasWeak&, HasWeak&&);
165TRAIT_IS_TRUE_2(__is_trivially_assignable, HasUnsafeUnretained&, HasUnsafeUnretained);
166TRAIT_IS_TRUE_2(__is_trivially_assignable, HasUnsafeUnretained&, HasUnsafeUnretained&&);
167
168// __is_trivally_constructible
169TRAIT_IS_FALSE(__is_trivially_constructible, __strong id);
170TRAIT_IS_FALSE(__is_trivially_constructible, __weak id);
171TRAIT_IS_FALSE(__is_trivially_constructible, __autoreleasing id);
172TRAIT_IS_TRUE(__is_trivially_constructible, __unsafe_unretained id);
173
174TRAIT_IS_FALSE_2(__is_trivially_constructible, __strong id, __strong id);
175TRAIT_IS_FALSE_2(__is_trivially_constructible, __strong id, __weak id);
176TRAIT_IS_FALSE_2(__is_trivially_constructible, __strong id, __autoreleasing id);
177TRAIT_IS_FALSE_2(__is_trivially_constructible, __strong id, __unsafe_unretained id);
178TRAIT_IS_FALSE_2(__is_trivially_constructible, __strong id, __strong id&&);
179TRAIT_IS_FALSE_2(__is_trivially_constructible, __strong id, __weak id&&);
180TRAIT_IS_FALSE_2(__is_trivially_constructible, __strong id, __autoreleasing id&&);
181TRAIT_IS_FALSE_2(__is_trivially_constructible, __strong id, __unsafe_unretained id&&);
182TRAIT_IS_FALSE_2(__is_trivially_constructible, __weak id, __strong id);
183TRAIT_IS_FALSE_2(__is_trivially_constructible, __weak id, __weak id);
184TRAIT_IS_FALSE_2(__is_trivially_constructible, __weak id, __autoreleasing id);
185TRAIT_IS_FALSE_2(__is_trivially_constructible, __weak id, __unsafe_unretained id);
186TRAIT_IS_FALSE_2(__is_trivially_constructible, __weak id, __strong id&&);
187TRAIT_IS_FALSE_2(__is_trivially_constructible, __weak id, __weak id&&);
188TRAIT_IS_FALSE_2(__is_trivially_constructible, __weak id, __autoreleasing id&&);
189TRAIT_IS_FALSE_2(__is_trivially_constructible, __weak id, __unsafe_unretained id&&);
190
191TRAIT_IS_FALSE_2(__is_trivially_constructible, __autoreleasing id, __strong id);
192TRAIT_IS_FALSE_2(__is_trivially_constructible, __autoreleasing id, __weak id);
193TRAIT_IS_FALSE_2(__is_trivially_constructible, __autoreleasing id, __autoreleasing id);
194TRAIT_IS_FALSE_2(__is_trivially_constructible, __autoreleasing id, __unsafe_unretained id);
195TRAIT_IS_FALSE_2(__is_trivially_constructible, __autoreleasing id, __strong id&&);
196TRAIT_IS_FALSE_2(__is_trivially_constructible, __autoreleasing id, __weak id&&);
197TRAIT_IS_FALSE_2(__is_trivially_constructible, __autoreleasing id, __autoreleasing id&&);
198TRAIT_IS_FALSE_2(__is_trivially_constructible, __autoreleasing id, __unsafe_unretained id&&);
199
200TRAIT_IS_TRUE_2(__is_trivially_constructible, __unsafe_unretained id, __strong id);
201TRAIT_IS_TRUE_2(__is_trivially_constructible, __unsafe_unretained id, __weak id);
202TRAIT_IS_TRUE_2(__is_trivially_constructible, __unsafe_unretained id, __autoreleasing id);
203TRAIT_IS_TRUE_2(__is_trivially_constructible, __unsafe_unretained id, __unsafe_unretained id);
204TRAIT_IS_TRUE_2(__is_trivially_constructible, __unsafe_unretained id, __strong id&&);
205TRAIT_IS_TRUE_2(__is_trivially_constructible, __unsafe_unretained id, __weak id&&);
206TRAIT_IS_TRUE_2(__is_trivially_constructible, __unsafe_unretained id, __autoreleasing id&&);
207TRAIT_IS_TRUE_2(__is_trivially_constructible, __unsafe_unretained id, __unsafe_unretained id&&);
208
209TRAIT_IS_FALSE_2(__is_trivially_constructible, HasStrong, HasStrong);
210TRAIT_IS_FALSE_2(__is_trivially_constructible, HasStrong, HasStrong&&);
211TRAIT_IS_FALSE_2(__is_trivially_constructible, HasWeak, HasWeak);
212TRAIT_IS_FALSE_2(__is_trivially_constructible, HasWeak, HasWeak&&);
213TRAIT_IS_TRUE_2(__is_trivially_constructible, HasUnsafeUnretained, HasUnsafeUnretained);
214TRAIT_IS_TRUE_2(__is_trivially_constructible, HasUnsafeUnretained, HasUnsafeUnretained&&);
215
216