[AMDGPU][True16][CodeGen] true16 codegen pattern for v_med3_u/i16 (#121850)
[llvm-project.git] / clang / test / SemaTemplate / attributes.cpp
blobdea19d09745ca234676ca4a7230ac488dc2012cb
1 // RUN: %clang_cc1 -std=gnu++11 -fsyntax-only -verify %s
2 // RUN: not %clang_cc1 -std=gnu++11 -ast-dump %s | FileCheck %s
4 namespace attribute_aligned {
5 template<int N>
6 struct X {
7 char c[1] __attribute__((__aligned__((N)))); // expected-error {{alignment is not a power of 2}}
8 };
10 template <bool X> struct check {
11 int check_failed[X ? 1 : -1]; // expected-error {{array with a negative size}}
14 template <int N> struct check_alignment {
15 typedef check<N == sizeof(X<N>)> t; // expected-note {{in instantiation}}
18 check_alignment<1>::t c1;
19 check_alignment<2>::t c2;
20 check_alignment<3>::t c3; // expected-note 2 {{in instantiation}}
21 check_alignment<4>::t c4;
23 template<unsigned Size, unsigned Align>
24 class my_aligned_storage
26 __attribute__((aligned(Align))) char storage[Size];
29 template<typename T>
30 class C {
31 public:
32 C() {
33 static_assert(sizeof(t) == sizeof(T), "my_aligned_storage size wrong");
34 static_assert(alignof(t) == alignof(T), "my_aligned_storage align wrong"); // expected-warning{{'alignof' applied to an expression is a GNU extension}}
37 private:
38 my_aligned_storage<sizeof(T), alignof(T)> t;
41 C<double> cd;
44 namespace PR9049 {
45 extern const void *CFRetain(const void *ref);
47 template<typename T> __attribute__((cf_returns_retained))
48 inline T WBCFRetain(T aValue) { return aValue ? (T)CFRetain(aValue) : (T)0; }
51 extern void CFRelease(const void *ref);
53 template<typename T>
54 inline void WBCFRelease(__attribute__((cf_consumed)) T aValue) { if(aValue) CFRelease(aValue); }
57 namespace attribute_annotate {
58 // CHECK: FunctionTemplateDecl {{.*}} HasAnnotations
59 // CHECK: AnnotateAttr {{.*}} "ANNOTATE_FOO"
60 // CHECK: AnnotateAttr {{.*}} "ANNOTATE_BAR"
61 // CHECK: FunctionDecl {{.*}} HasAnnotations
62 // CHECK: TemplateArgument type 'int'
63 // CHECK: AnnotateAttr {{.*}} "ANNOTATE_FOO"
64 // CHECK: AnnotateAttr {{.*}} "ANNOTATE_BAR"
65 template<typename T> [[clang::annotate("ANNOTATE_FOO"), clang::annotate("ANNOTATE_BAR")]] void HasAnnotations();
66 void UseAnnotations() { HasAnnotations<int>(); }
68 // CHECK: FunctionTemplateDecl {{.*}} HasStmtAnnotations
69 // CHECK: AnnotateAttr {{.*}} "ANNOTATE_BAZ"
70 // CHECK: FunctionDecl {{.*}} HasStmtAnnotations
71 // CHECK: TemplateArgument type 'int'
72 // CHECK: AnnotateAttr {{.*}} "ANNOTATE_BAZ"
73 template<typename T> void HasStmtAnnotations() {
74 int x = 0;
75 [[clang::annotate("ANNOTATE_BAZ")]] x++;
77 void UseStmtAnnotations() { HasStmtAnnotations<int>(); }
79 // CHECK: FunctionTemplateDecl {{.*}} HasPackAnnotations
80 // CHECK-NEXT: NonTypeTemplateParmDecl {{.*}} referenced 'int' depth 0 index 0 ... Is
81 // CHECK-NEXT: FunctionDecl {{.*}} HasPackAnnotations 'void ()'
82 // CHECK-NEXT: AnnotateAttr {{.*}} "ANNOTATE_BAZ"
83 // CHECK-NEXT: PackExpansionExpr {{.*}} '<dependent type>'
84 // CHECK-NEXT: DeclRefExpr {{.*}} 'int' NonTypeTemplateParm {{.*}} 'Is' 'int'
85 // CHECK-NEXT: FunctionDecl {{.*}} used HasPackAnnotations 'void ()'
86 // CHECK-NEXT: TemplateArgument{{.*}} pack
87 // CHECK-NEXT: TemplateArgument{{.*}} integral '1'
88 // CHECK-NEXT: TemplateArgument{{.*}} integral '2'
89 // CHECK-NEXT: TemplateArgument{{.*}} integral '3'
90 // CHECK-NEXT: AnnotateAttr {{.*}} "ANNOTATE_BAZ"
91 // CHECK-NEXT: ConstantExpr {{.*}} 'int'
92 // CHECK-NEXT: value: Int 1
93 // CHECK-NEXT: SubstNonTypeTemplateParmExpr {{.*}} 'int'
94 // CHECK-NEXT: NonTypeTemplateParmDecl {{.*}} referenced 'int' depth 0 index 0 ... Is
95 // CHECK-NEXT: IntegerLiteral {{.*}} 'int' 1
96 // CHECK-NEXT: ConstantExpr {{.*}} 'int'
97 // CHECK-NEXT: value: Int 2
98 // CHECK-NEXT: SubstNonTypeTemplateParmExpr {{.*}} 'int'
99 // CHECK-NEXT: NonTypeTemplateParmDecl {{.*}} referenced 'int' depth 0 index 0 ... Is
100 // CHECK-NEXT: IntegerLiteral {{.*}} 'int' 2
101 // CHECK-NEXT: ConstantExpr {{.*}} 'int'
102 // CHECK-NEXT: value: Int 3
103 // CHECK-NEXT: SubstNonTypeTemplateParmExpr {{.*}} 'int'
104 // CHECK-NEXT: NonTypeTemplateParmDecl {{.*}} referenced 'int' depth 0 index 0 ... Is
105 // CHECK-NEXT: IntegerLiteral {{.*}} 'int' 3
106 template <int... Is> [[clang::annotate("ANNOTATE_BAZ", Is...)]] void HasPackAnnotations();
107 void UsePackAnnotations() { HasPackAnnotations<1, 2, 3>(); }
109 // CHECK: FunctionTemplateDecl {{.*}} HasStmtPackAnnotations
110 // CHECK-NEXT: NonTypeTemplateParmDecl {{.*}} referenced 'int' depth 0 index 0 ... Is
111 // CHECK-NEXT: FunctionDecl {{.*}} HasStmtPackAnnotations 'void ()'
112 // CHECK: AttributedStmt {{.*}}
113 // CHECK-NEXT: AnnotateAttr {{.*}} "ANNOTATE_QUUX"
114 // CHECK-NEXT: PackExpansionExpr {{.*}} '<dependent type>'
115 // CHECK-NEXT: DeclRefExpr {{.*}} 'int' NonTypeTemplateParm {{.*}} 'Is' 'int'
116 // CHECK: FunctionDecl {{.*}} used HasStmtPackAnnotations 'void ()'
117 // CHECK-NEXT: TemplateArgument{{.*}} pack
118 // CHECK-NEXT: TemplateArgument{{.*}} integral '1'
119 // CHECK-NEXT: TemplateArgument{{.*}} integral '2'
120 // CHECK-NEXT: TemplateArgument{{.*}} integral '3'
121 // CHECK: AttributedStmt {{.*}}
122 // CHECK-NEXT: AnnotateAttr {{.*}} "ANNOTATE_QUUX"
123 // CHECK-NEXT: PackExpansionExpr {{.*}}
124 // CHECK-NEXT: SubstNonTypeTemplateParmPackExpr {{.*}}
125 // CHECK-NEXT: NonTypeTemplateParmDecl {{.*}} referenced 'int' depth 0 index 0 ... Is
126 // CHECK-NEXT: TemplateArgument pack '<1, 2, 3>'
127 // CHECK-NEXT: TemplateArgument integral '1'
128 // CHECK-NEXT: TemplateArgument integral '2'
129 // CHECK-NEXT: TemplateArgument integral '3'
130 template <int... Is> void HasStmtPackAnnotations() {
131 int x = 0;
132 [[clang::annotate("ANNOTATE_QUUX", Is...)]] x++;
134 void UseStmtPackAnnotations() { HasStmtPackAnnotations<1, 2, 3>(); }
136 template <int... Is> [[clang::annotate(Is...)]] void HasOnlyPackAnnotation() {} // expected-error {{expected string literal as argument of 'annotate' attribute}}
138 void UseOnlyPackAnnotations() {
139 HasOnlyPackAnnotation<>();
140 HasOnlyPackAnnotation<1>();
143 // CHECK: ClassTemplateDecl {{.*}} AnnotatedPackTemplateStruct
144 // CHECK-NEXT: TemplateTypeParmDecl {{.*}} typename depth 0 index 0 T
145 // CHECK-NEXT: NonTypeTemplateParmDecl {{.*}} referenced 'int' depth 0 index 1 ... Is
146 // CHECK-NEXT: CXXRecordDecl {{.*}} struct AnnotatedPackTemplateStruct definition
147 // CHECK-NEXT: DefinitionData
148 // CHECK-NEXT: DefaultConstructor
149 // CHECK-NEXT: CopyConstructor
150 // CHECK-NEXT: MoveConstructor
151 // CHECK-NEXT: CopyAssignment
152 // CHECK-NEXT: MoveAssignment
153 // CHECK-NEXT: Destructor
154 // CHECK-NEXT: AnnotateAttr {{.*}} "ANNOTATE_FOZ"
155 // CHECK-NEXT: PackExpansionExpr {{.*}} '<dependent type>'
156 // CHECK-NEXT: DeclRefExpr {{.*}} 'int' NonTypeTemplateParm {{.*}} 'Is' 'int'
157 // CHECK-NEXT: CXXRecordDecl {{.*}} implicit struct AnnotatedPackTemplateStruct
158 // CHECK-NEXT: ClassTemplateSpecializationDecl {{.*}} struct AnnotatedPackTemplateStruct definition
159 // CHECK-NEXT: DefinitionData
160 // CHECK-NEXT: DefaultConstructor
161 // CHECK-NEXT: CopyConstructor
162 // CHECK-NEXT: MoveConstructor
163 // CHECK-NEXT: CopyAssignment
164 // CHECK-NEXT: MoveAssignment
165 // CHECK-NEXT: Destructor
166 // CHECK-NEXT: TemplateArgument{{.*}} type 'int'
167 // CHECK-NEXT: BuiltinType {{.*}} 'int'
168 // CHECK-NEXT: TemplateArgument{{.*}} pack
169 // CHECK-NEXT: TemplateArgument{{.*}} integral '1'
170 // CHECK-NEXT: TemplateArgument{{.*}} integral '2'
171 // CHECK-NEXT: TemplateArgument{{.*}} integral '3'
172 // CHECK-NEXT: AnnotateAttr {{.*}} "ANNOTATE_BOO"
173 // CHECK-NEXT: ConstantExpr {{.*}} 'int'
174 // CHECK-NEXT: value: Int 1
175 // CHECK-NEXT: SubstNonTypeTemplateParmExpr {{.*}} 'int'
176 // CHECK-NEXT: NonTypeTemplateParmDecl {{.*}} referenced 'int' depth 0 index 0 ... Is
177 // CHECK-NEXT: IntegerLiteral {{.*}} 'int' 1
178 // CHECK-NEXT: ConstantExpr {{.*}} 'int'
179 // CHECK-NEXT: value: Int 2
180 // CHECK-NEXT: SubstNonTypeTemplateParmExpr {{.*}} 'int'
181 // CHECK-NEXT: NonTypeTemplateParmDecl {{.*}} referenced 'int' depth 0 index 0 ... Is
182 // CHECK-NEXT: IntegerLiteral {{.*}} 'int' 2
183 // CHECK-NEXT: ConstantExpr {{.*}} 'int'
184 // CHECK-NEXT: value: Int 3
185 // CHECK-NEXT: SubstNonTypeTemplateParmExpr {{.*}} 'int'
186 // CHECK-NEXT: NonTypeTemplateParmDecl {{.*}} referenced 'int' depth 0 index 0 ... Is
187 // CHECK-NEXT: IntegerLiteral {{.*}} 'int' 3
188 // CHECK-NEXT: CXXRecordDecl {{.*}} implicit struct AnnotatedPackTemplateStruct
189 // CHECK-NEXT: ClassTemplateSpecializationDecl {{.*}} struct AnnotatedPackTemplateStruct definition
190 // CHECK-NEXT: DefinitionData
191 // CHECK-NEXT: DefaultConstructor
192 // CHECK-NEXT: CopyConstructor
193 // CHECK-NEXT: MoveConstructor
194 // CHECK-NEXT: CopyAssignment
195 // CHECK-NEXT: MoveAssignment
196 // CHECK-NEXT: Destructor
197 // CHECK-NEXT: TemplateArgument type 'float'
198 // CHECK-NEXT: BuiltinType {{.*}} 'float'
199 // CHECK-NEXT: TemplateArgument{{.*}} pack
200 // CHECK-NEXT: TemplateArgument{{.*}} integral '3'
201 // CHECK-NEXT: TemplateArgument{{.*}} integral '2'
202 // CHECK-NEXT: TemplateArgument{{.*}} integral '1'
203 // CHECK-NEXT: AnnotateAttr {{.*}} "ANNOTATE_FOZ"
204 // CHECK-NEXT: ConstantExpr {{.*}} 'int'
205 // CHECK-NEXT: value: Int 4
206 // CHECK-NEXT: IntegerLiteral {{.*}} 'int' 4
207 // CHECK-NEXT: ConstantExpr {{.*}} 'int'
208 // CHECK-NEXT: value: Int 5
209 // CHECK-NEXT: IntegerLiteral {{.*}} 'int' 5
210 // CHECK-NEXT: ConstantExpr {{.*}} 'int'
211 // CHECK-NEXT: value: Int 6
212 // CHECK-NEXT: IntegerLiteral {{.*}} 'int' 6
213 // CHECK-NEXT: CXXRecordDecl {{.*}} implicit struct AnnotatedPackTemplateStruct
214 // CHECK-NEXT: ClassTemplateSpecializationDecl {{.*}} struct AnnotatedPackTemplateStruct definition
215 // CHECK-NEXT: DefinitionData
216 // CHECK-NEXT: DefaultConstructor
217 // CHECK-NEXT: CopyConstructor
218 // CHECK-NEXT: MoveConstructor
219 // CHECK-NEXT: CopyAssignment
220 // CHECK-NEXT: MoveAssignment
221 // CHECK-NEXT: Destructor
222 // CHECK-NEXT: TemplateArgument type 'bool'
223 // CHECK-NEXT: BuiltinType {{.*}} 'bool'
224 // CHECK-NEXT: TemplateArgument{{.*}} pack
225 // CHECK-NEXT: TemplateArgument{{.*}} integral '7'
226 // CHECK-NEXT: TemplateArgument{{.*}} integral '8'
227 // CHECK-NEXT: TemplateArgument{{.*}} integral '9'
228 // CHECK-NEXT: AnnotateAttr {{.*}} "ANNOTATE_FOZ"
229 // CHECK-NEXT: ConstantExpr {{.*}} 'int'
230 // CHECK-NEXT: value: Int 7
231 // CHECK-NEXT: SubstNonTypeTemplateParmExpr {{.*}} 'int'
232 // CHECK-NEXT: NonTypeTemplateParmDecl {{.*}} referenced 'int' depth 0 index 1 ... Is
233 // CHECK-NEXT: IntegerLiteral {{.*}} 'int' 7
234 // CHECK-NEXT: ConstantExpr {{.*}} 'int'
235 // CHECK-NEXT: value: Int 8
236 // CHECK-NEXT: SubstNonTypeTemplateParmExpr {{.*}} 'int'
237 // CHECK-NEXT: NonTypeTemplateParmDecl {{.*}} referenced 'int' depth 0 index 1 ... Is
238 // CHECK-NEXT: IntegerLiteral {{.*}} 'int' 8
239 // CHECK-NEXT: ConstantExpr {{.*}} 'int'
240 // CHECK-NEXT: value: Int 9
241 // CHECK-NEXT: SubstNonTypeTemplateParmExpr {{.*}} 'int'
242 // CHECK-NEXT: NonTypeTemplateParmDecl {{.*}} referenced 'int' depth 0 index 1 ... Is
243 // CHECK-NEXT: IntegerLiteral {{.*}} 'int' 9
244 // CHECK-NEXT: CXXRecordDecl {{.*}} implicit struct AnnotatedPackTemplateStruct
245 // CHECK-NEXT: ClassTemplateSpecializationDecl {{.*}} struct AnnotatedPackTemplateStruct definition
246 // CHECK-NEXT: DefinitionData
247 // CHECK-NEXT: DefaultConstructor
248 // CHECK-NEXT: CopyConstructor
249 // CHECK-NEXT: MoveConstructor
250 // CHECK-NEXT: CopyAssignment
251 // CHECK-NEXT: MoveAssignment
252 // CHECK-NEXT: Destructor
253 // CHECK-NEXT: TemplateArgument type 'char'
254 // CHECK-NEXT: BuiltinType {{.*}} 'char'
255 // CHECK-NEXT: TemplateArgument{{.*}} pack
256 // CHECK-NEXT: TemplateArgument{{.*}} integral '1'
257 // CHECK-NEXT: TemplateArgument{{.*}} integral '2'
258 // CHECK-NEXT: TemplateArgument{{.*}} integral '3'
259 // CHECK-NEXT: CXXRecordDecl {{.*}} implicit struct AnnotatedPackTemplateStruct
260 // CHECK-NEXT: ClassTemplateSpecializationDecl {{.*}} struct AnnotatedPackTemplateStruct definition
261 // CHECK-NEXT: DefinitionData
262 // CHECK-NEXT: DefaultConstructor
263 // CHECK-NEXT: CopyConstructor
264 // CHECK-NEXT: MoveConstructor
265 // CHECK-NEXT: CopyAssignment
266 // CHECK-NEXT: MoveAssignment
267 // CHECK-NEXT: Destructor
268 // CHECK-NEXT: TemplateArgument{{.*}} type 'char'
269 // CHECK-NEXT: BuiltinType {{.*}} 'char'
270 // CHECK-NEXT: TemplateArgument{{.*}} pack
271 // CHECK-NEXT: CXXRecordDecl {{.*}} implicit struct AnnotatedPackTemplateStruct
272 // CHECK-NEXT: ClassTemplatePartialSpecializationDecl {{.*}} struct AnnotatedPackTemplateStruct definition
273 // CHECK-NEXT: DefinitionData
274 // CHECK-NEXT: DefaultConstructor
275 // CHECK-NEXT: CopyConstructor
276 // CHECK-NEXT: MoveConstructor
277 // CHECK-NEXT: CopyAssignment
278 // CHECK-NEXT: MoveAssignment
279 // CHECK-NEXT: Destructor
280 // CHECK-NEXT: TemplateArgument{{.*}} type 'int'
281 // CHECK-NEXT: BuiltinType {{.*}} 'int'
282 // CHECK-NEXT: TemplateArgument{{.*}} pack
283 // CHECK-NEXT: TemplateArgument{{.*}} expr
284 // CHECK-NEXT: PackExpansionExpr {{.*}} 'int'
285 // CHECK-NEXT: DeclRefExpr {{.*}} 'int' NonTypeTemplateParm {{.*}} 'Is' 'int'
286 // CHECK-NEXT: NonTypeTemplateParmDecl {{.*}} referenced 'int' depth 0 index 0 ... Is
287 // CHECK-NEXT: AnnotateAttr {{.*}} "ANNOTATE_BOO"
288 // CHECK-NEXT: PackExpansionExpr {{.*}} '<dependent type>'
289 // CHECK-NEXT: DeclRefExpr {{.*}} 'int' NonTypeTemplateParm {{.*}} 'Is' 'int'
290 // CHECK-NEXT: CXXRecordDecl {{.*}} implicit struct AnnotatedPackTemplateStruct
291 // CHECK-NEXT: ClassTemplatePartialSpecializationDecl {{.*}} struct AnnotatedPackTemplateStruct definition
292 // CHECK-NEXT: DefinitionData
293 // CHECK-NEXT: DefaultConstructor
294 // CHECK-NEXT: CopyConstructor
295 // CHECK-NEXT: MoveConstructor
296 // CHECK-NEXT: CopyAssignment
297 // CHECK-NEXT: MoveAssignment
298 // CHECK-NEXT: Destructor
299 // CHECK-NEXT: TemplateArgument{{.*}} type 'float'
300 // CHECK-NEXT: BuiltinType {{.*}} 'float'
301 // CHECK-NEXT: TemplateArgument{{.*}} pack
302 // CHECK-NEXT: TemplateArgument{{.*}} expr
303 // CHECK-NEXT: PackExpansionExpr {{.*}} 'int'
304 // CHECK-NEXT: DeclRefExpr {{.*}} 'int' NonTypeTemplateParm {{.*}} 'Is' 'int'
305 // CHECK-NEXT: NonTypeTemplateParmDecl {{.*}} referenced 'int' depth 0 index 0 ... Is
306 // CHECK-NEXT: AnnotateAttr {{.*}} "ANNOTATE_FOZ"
307 // CHECK-NEXT: ConstantExpr {{.*}} 'int'
308 // CHECK-NEXT: value: Int 4
309 // CHECK-NEXT: IntegerLiteral {{.*}} 'int' 4
310 // CHECK-NEXT: ConstantExpr {{.*}} 'int'
311 // CHECK-NEXT: value: Int 5
312 // CHECK-NEXT: IntegerLiteral {{.*}} 'int' 5
313 // CHECK-NEXT: ConstantExpr {{.*}} 'int'
314 // CHECK-NEXT: value: Int 6
315 // CHECK-NEXT: IntegerLiteral {{.*}} 'int' 6
316 // CHECK-NEXT: CXXRecordDecl {{.*}} implicit struct AnnotatedPackTemplateStruct
317 template <typename T, int... Is> struct [[clang::annotate("ANNOTATE_FOZ", Is...)]] AnnotatedPackTemplateStruct{};
318 template <int... Is> struct [[clang::annotate("ANNOTATE_BOO", Is...)]] AnnotatedPackTemplateStruct<int, Is...>{};
319 template <int... Is> struct [[clang::annotate("ANNOTATE_FOZ", 4, 5, 6)]] AnnotatedPackTemplateStruct<float, Is...>{};
320 template <int... Is> struct [[clang::annotate(Is...)]] AnnotatedPackTemplateStruct<char, Is...>{}; // expected-error {{expected string literal as argument of 'annotate' attribute}}
321 void UseAnnotatedPackTemplateStructSpecializations() {
322 AnnotatedPackTemplateStruct<int, 1, 2, 3> Instance1{};
323 AnnotatedPackTemplateStruct<float, 3, 2, 1> Instance2{};
324 AnnotatedPackTemplateStruct<bool, 7, 8, 9> Instance3{};
325 AnnotatedPackTemplateStruct<char, 1, 2, 3> Instance4{};
326 AnnotatedPackTemplateStruct<char> Instance5{};
329 // CHECK: ClassTemplateDecl {{.*}} InvalidAnnotatedPackTemplateStruct
330 // CHECK-NEXT: TemplateTypeParmDecl {{.*}} typename depth 0 index 0 T
331 // CHECK-NEXT: NonTypeTemplateParmDecl {{.*}} 'int' depth 0 index 1 ... Is
332 // CHECK-NEXT: CXXRecordDecl {{.*}} struct InvalidAnnotatedPackTemplateStruct definition
333 // CHECK-NEXT: DefinitionData
334 // CHECK-NEXT: DefaultConstructor
335 // CHECK-NEXT: CopyConstructor
336 // CHECK-NEXT: MoveConstructor
337 // CHECK-NEXT: CopyAssignment
338 // CHECK-NEXT: MoveAssignment
339 // CHECK-NEXT: Destructor
340 // CHECK-NEXT: CXXRecordDecl {{.*}} implicit struct InvalidAnnotatedPackTemplateStruct
341 // CHECK-NEXT: ClassTemplateSpecialization {{.*}} 'InvalidAnnotatedPackTemplateStruct'
342 // CHECK-NEXT: ClassTemplateSpecializationDecl {{.*}} struct InvalidAnnotatedPackTemplateStruct definition
343 // CHECK-NEXT: DefinitionData
344 // CHECK-NEXT: DefaultConstructor
345 // CHECK-NEXT: CopyConstructor
346 // CHECK-NEXT: MoveConstructor
347 // CHECK-NEXT: CopyAssignment
348 // CHECK-NEXT: MoveAssignment
349 // CHECK-NEXT: Destructor
350 // CHECK-NEXT: TemplateArgument{{.*}} type 'int'
351 // CHECK-NEXT: BuiltinType {{.*}} 'int'
352 // CHECK-NEXT: TemplateArgument{{.*}} pack
353 // CHECK-NEXT: TemplateArgument{{.*}} integral '1'
354 // CHECK-NEXT: TemplateArgument{{.*}} integral '2'
355 // CHECK-NEXT: TemplateArgument{{.*}} integral '3'
356 // CHECK-NEXT: AnnotateAttr {{.*}} "ANNOTATE_BIR"
357 // CHECK-NEXT: ConstantExpr {{.*}} 'int'
358 // CHECK-NEXT: value: Int 1
359 // CHECK-NEXT: SubstNonTypeTemplateParmExpr {{.*}} 'int'
360 // CHECK-NEXT: NonTypeTemplateParmDecl {{.*}} referenced 'int' depth 0 index 0 ... Is
361 // CHECK-NEXT: IntegerLiteral {{.*}} 'int' 1
362 // CHECK-NEXT: ConstantExpr {{.*}} 'int'
363 // CHECK-NEXT: value: Int 2
364 // CHECK-NEXT: SubstNonTypeTemplateParmExpr {{.*}} 'int'
365 // CHECK-NEXT: NonTypeTemplateParmDecl {{.*}} referenced 'int' depth 0 index 0 ... Is
366 // CHECK-NEXT: IntegerLiteral {{.*}} 'int' 2
367 // CHECK-NEXT: ConstantExpr {{.*}} 'int'
368 // CHECK-NEXT: value: Int 3
369 // CHECK-NEXT: SubstNonTypeTemplateParmExpr {{.*}} 'int'
370 // CHECK-NEXT: NonTypeTemplateParmDecl {{.*}} referenced 'int' depth 0 index 0 ... Is
371 // CHECK-NEXT: IntegerLiteral {{.*}} 'int' 3
372 // CHECK-NEXT: CXXRecordDecl {{.*}} implicit struct InvalidAnnotatedPackTemplateStruct
373 // CHECK-NEXT: ClassTemplateSpecializationDecl {{.*}} struct InvalidAnnotatedPackTemplateStruct definition
374 // CHECK-NEXT: DefinitionData
375 // CHECK-NEXT: DefaultConstructor
376 // CHECK-NEXT: CopyConstructor
377 // CHECK-NEXT: MoveConstructor
378 // CHECK-NEXT: CopyAssignment
379 // CHECK-NEXT: MoveAssignment
380 // CHECK-NEXT: Destructor
381 // CHECK-NEXT: TemplateArgument{{.*}} type 'float'
382 // CHECK-NEXT: BuiltinType {{.*}} 'float'
383 // CHECK-NEXT: TemplateArgument{{.*}} pack
384 // CHECK-NEXT: TemplateArgument{{.*}} integral '3'
385 // CHECK-NEXT: TemplateArgument{{.*}} integral '2'
386 // CHECK-NEXT: TemplateArgument{{.*}} integral '1'
387 // CHECK-NEXT: CXXRecordDecl {{.*}} implicit struct InvalidAnnotatedPackTemplateStruct
388 // CHECK-NEXT: ClassTemplateSpecializationDecl {{.*}} struct InvalidAnnotatedPackTemplateStruct definition
389 // CHECK-NEXT: DefinitionData
390 // CHECK-NEXT: DefaultConstructor
391 // CHECK-NEXT: CopyConstructor
392 // CHECK-NEXT: MoveConstructor
393 // CHECK-NEXT: CopyAssignment
394 // CHECK-NEXT: MoveAssignment
395 // CHECK-NEXT: Destructor
396 // CHECK-NEXT: TemplateArgument{{.*}} type 'bool'
397 // CHECK-NEXT: BuiltinType {{.*}} 'bool'
398 // CHECK-NEXT: TemplateArgument{{.*}} pack
399 // CHECK-NEXT: TemplateArgument{{.*}} integral '7'
400 // CHECK-NEXT: TemplateArgument{{.*}} integral '8'
401 // CHECK-NEXT: TemplateArgument{{.*}} integral '9'
402 // CHECK-NEXT: CXXRecordDecl {{.*}} implicit struct InvalidAnnotatedPackTemplateStruct
403 // CHECK-NEXT: ClassTemplateSpecializationDecl {{.*}} struct InvalidAnnotatedPackTemplateStruct definition
404 // CHECK-NEXT: DefinitionData
405 // CHECK-NEXT: DefaultConstructor
406 // CHECK-NEXT: CopyConstructor
407 // CHECK-NEXT: MoveConstructor
408 // CHECK-NEXT: CopyAssignment
409 // CHECK-NEXT: MoveAssignment
410 // CHECK-NEXT: Destructor
411 // CHECK-NEXT: TemplateArgument{{.*}} type 'bool'
412 // CHECK-NEXT: BuiltinType {{.*}} 'bool'
413 // CHECK-NEXT: TemplateArgument{{.*}} pack
414 // CHECK-NEXT: CXXRecordDecl {{.*}} implicit struct InvalidAnnotatedPackTemplateStruct
415 // CHECK-NEXT: ClassTemplatePartialSpecializationDecl {{.*}} struct InvalidAnnotatedPackTemplateStruct definition
416 // CHECK-NEXT: DefinitionData
417 // CHECK-NEXT: DefaultConstructor
418 // CHECK-NEXT: CopyConstructor
419 // CHECK-NEXT: MoveConstructor
420 // CHECK-NEXT: CopyAssignment
421 // CHECK-NEXT: MoveAssignment
422 // CHECK-NEXT: Destructor
423 // CHECK-NEXT: TemplateArgument{{.*}} type 'int'
424 // CHECK-NEXT: BuiltinType {{.*}} 'int'
425 // CHECK-NEXT: TemplateArgument{{.*}} pack
426 // CHECK-NEXT: TemplateArgument{{.*}} expr
427 // CHECK-NEXT: PackExpansionExpr {{.*}} 'int'
428 // CHECK-NEXT: DeclRefExpr {{.*}} 'int' NonTypeTemplateParm {{.*}} 'Is' 'int'
429 // CHECK-NEXT: NonTypeTemplateParmDecl {{.*}} referenced 'int' depth 0 index 0 ... Is
430 // CHECK-NEXT: AnnotateAttr {{.*}} "ANNOTATE_BIR"
431 // CHECK-NEXT: PackExpansionExpr {{.*}} '<dependent type>'
432 // CHECK-NEXT: DeclRefExpr {{.*}} 'int' NonTypeTemplateParm {{.*}} 'Is' 'int'
433 // CHECK-NEXT: CXXRecordDecl {{.*}} implicit struct InvalidAnnotatedPackTemplateStruct
434 // CHECK-NEXT: ClassTemplatePartialSpecializationDecl {{.*}} struct InvalidAnnotatedPackTemplateStruct definition
435 // CHECK-NEXT: DefinitionData
436 // CHECK-NEXT: DefaultConstructor
437 // CHECK-NEXT: CopyConstructor
438 // CHECK-NEXT: MoveConstructor
439 // CHECK-NEXT: CopyAssignment
440 // CHECK-NEXT: MoveAssignment
441 // CHECK-NEXT: Destructor
442 // CHECK-NEXT: TemplateArgument{{.*}} type 'float'
443 // CHECK-NEXT: BuiltinType {{.*}} 'float'
444 // CHECK-NEXT: TemplateArgument{{.*}} pack
445 // CHECK-NEXT: TemplateArgument{{.*}} expr
446 // CHECK-NEXT: PackExpansionExpr {{.*}} 'int'
447 // CHECK-NEXT: DeclRefExpr {{.*}} 'int' NonTypeTemplateParm {{.*}} 'Is' 'int'
448 // CHECK-NEXT: NonTypeTemplateParmDecl {{.*}} referenced 'int' depth 0 index 0 ... Is
449 // CHECK-NEXT: CXXRecordDecl {{.*}} implicit struct InvalidAnnotatedPackTemplateStruct
450 // CHECK-NEXT: ClassTemplateSpecializationDecl {{.*}} struct InvalidAnnotatedPackTemplateStruct definition
451 // CHECK-NEXT: DefinitionData
452 // CHECK-NEXT: DefaultConstructor
453 // CHECK-NEXT: CopyConstructor
454 // CHECK-NEXT: MoveConstructor
455 // CHECK-NEXT: CopyAssignment
456 // CHECK-NEXT: MoveAssignment
457 // CHECK-NEXT: Destructor
458 // CHECK-NEXT: TemplateArgument{{.*}} type 'char'
459 // CHECK-NEXT: BuiltinType {{.*}} 'char'
460 // CHECK-NEXT: TemplateArgument{{.*}} pack
461 // CHECK-NEXT: TemplateArgument{{.*}} integral '5'
462 // CHECK-NEXT: TemplateArgument{{.*}} integral '6'
463 // CHECK-NEXT: TemplateArgument{{.*}} integral '7'
464 // CHECK-NEXT: CXXRecordDecl {{.*}} implicit struct InvalidAnnotatedPackTemplateStruct
465 template <typename T, int... Is> struct InvalidAnnotatedPackTemplateStruct{};
466 template <int... Is> struct [[clang::annotate("ANNOTATE_BIR", Is...)]] InvalidAnnotatedPackTemplateStruct<int, Is...>{};
467 template <int... Is> struct InvalidAnnotatedPackTemplateStruct<float, Is...> {};
468 template <> struct InvalidAnnotatedPackTemplateStruct<char, 5, 6, 7> {};
469 void UseInvalidAnnotatedPackTemplateStruct() {
470 InvalidAnnotatedPackTemplateStruct<int, 1, 2, 3> Instance1{};
471 InvalidAnnotatedPackTemplateStruct<float, 3, 2, 1> Instance2{};
472 InvalidAnnotatedPackTemplateStruct<char, 5, 6, 7> Instance3{};
473 InvalidAnnotatedPackTemplateStruct<bool, 7, 8, 9> Instance4{};
474 InvalidAnnotatedPackTemplateStruct<bool> Instance5{};
477 // CHECK: FunctionTemplateDecl {{.*}} RedeclaredAnnotatedFunc
478 // CHECK-NEXT: NonTypeTemplateParmDecl {{.*}} referenced 'int' depth 0 index 0 ... Is
479 // CHECK-NEXT: FunctionDecl {{.*}} RedeclaredAnnotatedFunc 'void ()'
480 // CHECK-NEXT: AnnotateAttr {{.*}} "ANNOTATE_FAR"
481 // CHECK-NEXT: PackExpansionExpr {{.*}} '<dependent type>'
482 // CHECK-NEXT: DeclRefExpr {{.*}} 'int' NonTypeTemplateParm {{.*}} 'Is' 'int'
483 // CHECK-NEXT: FunctionDecl {{.*}} used RedeclaredAnnotatedFunc 'void ()'
484 // CHECK-NEXT: TemplateArgument{{.*}} pack
485 // CHECK-NEXT: TemplateArgument{{.*}} integral '1'
486 // CHECK-NEXT: TemplateArgument{{.*}} integral '2'
487 // CHECK-NEXT: TemplateArgument{{.*}} integral '3'
488 // CHECK-NEXT: CompoundStmt
489 // CHECK-NEXT: AnnotateAttr {{.*}} "ANNOTATE_FAR"
490 // CHECK-NEXT: ConstantExpr {{.*}} 'int'
491 // CHECK-NEXT: value: Int 1
492 // CHECK-NEXT: SubstNonTypeTemplateParmExpr {{.*}} 'int'
493 // CHECK-NEXT: NonTypeTemplateParmDecl {{.*}} referenced 'int' depth 0 index 0 ... Is
494 // CHECK-NEXT: IntegerLiteral {{.*}} 'int' 1
495 // CHECK-NEXT: ConstantExpr {{.*}} 'int'
496 // CHECK-NEXT: value: Int 2
497 // CHECK-NEXT: SubstNonTypeTemplateParmExpr {{.*}} 'int'
498 // CHECK-NEXT: NonTypeTemplateParmDecl {{.*}} referenced 'int' depth 0 index 0 ... Is
499 // CHECK-NEXT: IntegerLiteral {{.*}} 'int' 2
500 // CHECK-NEXT: ConstantExpr {{.*}} 'int'
501 // CHECK-NEXT: value: Int 3
502 // CHECK-NEXT: SubstNonTypeTemplateParmExpr {{.*}} 'int'
503 // CHECK-NEXT: NonTypeTemplateParmDecl {{.*}} referenced 'int' depth 0 index 0 ... Is
504 // CHECK-NEXT: IntegerLiteral {{.*}} 'int' 3
505 // CHECK-NEXT: AnnotateAttr {{.*}} "ANNOTATE_FIZ"
506 // CHECK-NEXT: ConstantExpr {{.*}} 'int'
507 // CHECK-NEXT: value: Int 4
508 // CHECK-NEXT: IntegerLiteral {{.*}} 'int' 4
509 // CHECK-NEXT: ConstantExpr {{.*}} 'int'
510 // CHECK-NEXT: value: Int 5
511 // CHECK-NEXT: IntegerLiteral {{.*}} 'int' 5
512 // CHECK-NEXT: AnnotateAttr {{.*}} "ANNOTATE_BOZ"
513 // CHECK-NEXT: ConstantExpr {{.*}} 'int'
514 // CHECK-NEXT: value: Int 6
515 // CHECK-NEXT: IntegerLiteral {{.*}} 'int' 6
516 // CHECK-NEXT: FunctionTemplateDecl {{.*}} prev {{.*}} RedeclaredAnnotatedFunc
517 // CHECK-NEXT: NonTypeTemplateParmDecl {{.*}} referenced 'int' depth 0 index 0 ... Is
518 // CHECK-NEXT: FunctionDecl {{.*}} prev {{.*}} RedeclaredAnnotatedFunc 'void ()'
519 // CHECK-NEXT: AnnotateAttr {{.*}} Inherited "ANNOTATE_FAR"
520 // CHECK-NEXT: PackExpansionExpr {{.*}} '<dependent type>'
521 // CHECK-NEXT: DeclRefExpr {{.*}} 'int' NonTypeTemplateParm {{.*}} 'Is' 'int'
522 // CHECK-NEXT: AnnotateAttr {{.*}} "ANNOTATE_BOZ"
523 // CHECK-NEXT: PackExpansionExpr {{.*}} '<dependent type>'
524 // CHECK-NEXT: DeclRefExpr {{.*}} 'int' NonTypeTemplateParm {{.*}} 'Is' 'int'
525 // CHECK-NEXT: Function {{.*}} 'RedeclaredAnnotatedFunc' 'void ()'
526 // CHECK-NEXT: FunctionTemplateDecl {{.*}} prev {{.*}} RedeclaredAnnotatedFunc
527 // CHECK-NEXT: NonTypeTemplateParmDecl {{.*}} 'int' depth 0 index 0 ... Is
528 // CHECK-NEXT: FunctionDecl {{.*}} prev {{.*}} RedeclaredAnnotatedFunc 'void ()'
529 // CHECK-NEXT: AnnotateAttr {{.*}} Inherited "ANNOTATE_FAR"
530 // CHECK-NEXT: PackExpansionExpr {{.*}} '<dependent type>'
531 // CHECK-NEXT: DeclRefExpr {{.*}} 'int' NonTypeTemplateParm {{.*}} 'Is' 'int'
532 // CHECK-NEXT: AnnotateAttr {{.*}} Inherited "ANNOTATE_BOZ"
533 // CHECK-NEXT: PackExpansionExpr {{.*}} '<dependent type>'
534 // CHECK-NEXT: DeclRefExpr {{.*}} 'int' NonTypeTemplateParm {{.*}} 'Is' 'int'
535 // CHECK-NEXT: AnnotateAttr {{.*}} "ANNOTATE_FIZ"
536 // CHECK-NEXT: ConstantExpr {{.*}} 'int'
537 // CHECK-NEXT: value: Int 4
538 // CHECK-NEXT: IntegerLiteral {{.*}} 'int' 4
539 // CHECK-NEXT: ConstantExpr {{.*}} 'int'
540 // CHECK-NEXT: value: Int 5
541 // CHECK-NEXT: IntegerLiteral {{.*}} 'int' 5
542 // CHECK-NEXT: Function {{.*}} 'RedeclaredAnnotatedFunc' 'void ()'
543 // CHECK-NEXT: FunctionTemplateDecl {{.*}} prev {{.*}} RedeclaredAnnotatedFunc
544 // CHECK-NEXT: NonTypeTemplateParmDecl {{.*}} 'int' depth 0 index 0 ... Is
545 // CHECK-NEXT: FunctionDecl {{.*}} prev {{.*}} RedeclaredAnnotatedFunc 'void ()'
546 // CHECK-NEXT: CompoundStmt
547 // CHECK-NEXT: AnnotateAttr {{.*}} Inherited "ANNOTATE_FAR"
548 // CHECK-NEXT: PackExpansionExpr {{.*}} '<dependent type>'
549 // CHECK-NEXT: DeclRefExpr {{.*}} 'int' NonTypeTemplateParm {{.*}} 'Is' 'int'
550 // CHECK-NEXT: AnnotateAttr {{.*}} Inherited "ANNOTATE_FIZ"
551 // CHECK-NEXT: ConstantExpr {{.*}} 'int'
552 // CHECK-NEXT: value: Int 4
553 // CHECK-NEXT: IntegerLiteral {{.*}} 'int' 4
554 // CHECK-NEXT: ConstantExpr {{.*}} 'int'
555 // CHECK-NEXT: value: Int 5
556 // CHECK-NEXT: IntegerLiteral {{.*}} 'int' 5
557 // CHECK-NEXT: AnnotateAttr {{.*}} "ANNOTATE_BOZ"
558 // CHECK-NEXT: ConstantExpr {{.*}} 'int'
559 // CHECK-NEXT: value: Int 6
560 // CHECK-NEXT: IntegerLiteral {{.*}} 'int' 6
561 // CHECK-NEXT: Function {{.*}} 'RedeclaredAnnotatedFunc' 'void ()'
562 // CHECK-NEXT: EmptyDecl
563 template <int... Is> [[clang::annotate("ANNOTATE_FAR", Is...)]] void RedeclaredAnnotatedFunc();
564 template <int... Is> [[clang::annotate("ANNOTATE_BOZ", Is...)]] void RedeclaredAnnotatedFunc();
565 template <int... Is> [[clang::annotate("ANNOTATE_FIZ", 4, 5)]] void RedeclaredAnnotatedFunc();
566 template <int... Is> [[clang::annotate("ANNOTATE_BOZ", 6)]] void RedeclaredAnnotatedFunc(){};
567 void UseRedeclaredAnnotatedFunc() {
568 RedeclaredAnnotatedFunc<1, 2, 3>();
571 } // namespace attribute_annotate
573 namespace preferred_name {
574 int x [[clang::preferred_name("frank")]]; // expected-error {{expected a type}}
575 int y [[clang::preferred_name(int)]]; // expected-warning {{'preferred_name' attribute only applies to class templates}}
576 struct [[clang::preferred_name(int)]] A; // expected-warning {{'preferred_name' attribute only applies to class templates}}
577 template<typename T> struct [[clang::preferred_name(int)]] B; // expected-error {{argument 'int' to 'preferred_name' attribute is not a typedef for a specialization of 'B'}}
578 template<typename T> struct C;
579 using X = C<int>; // expected-note {{'X' declared here}}
580 typedef C<float> Y;
581 using Z = const C<double>; // expected-note {{'Z' declared here}}
582 template<typename T> struct [[clang::preferred_name(C<int>)]] C; // expected-error {{argument 'C<int>' to 'preferred_name' attribute is not a typedef for a specialization of 'C'}}
583 template<typename T> struct [[clang::preferred_name(X), clang::preferred_name(Y)]] C;
584 template<typename T> struct [[clang::preferred_name(const X)]] C; // expected-error {{argument 'const X'}}
585 template<typename T> struct [[clang::preferred_name(Z)]] C; // expected-error {{argument 'Z' (aka 'const C<double>')}}
586 template<typename T> struct C {};
588 // CHECK: ClassTemplateDecl {{.*}} <line:[[@LINE-10]]:{{.*}} C
589 // CHECK: ClassTemplateSpecializationDecl {{.*}} struct C definition
590 // CHECK: TemplateArgument type 'int'
591 // CHECK-NOT: PreferredNameAttr
592 // CHECK: PreferredNameAttr {{.*}} X
593 // CHECK-NOT: PreferredNameAttr
594 // CHECK: CXXRecordDecl
595 // CHECK: ClassTemplateSpecializationDecl {{.*}} struct C definition
596 // CHECK: TemplateArgument type 'float'
597 // CHECK-NOT: PreferredNameAttr
598 // CHECK: PreferredNameAttr {{.*}} Y
599 // CHECK-NOT: PreferredNameAttr
600 // CHECK: CXXRecordDecl
601 // CHECK: ClassTemplateSpecializationDecl {{.*}} struct C definition
602 // CHECK: TemplateArgument type 'double'
603 // CHECK-NOT: PreferredNameAttr
604 // CHECK: CXXRecordDecl
606 // Check this doesn't cause us to instantiate the same attribute multiple times.
607 C<float> *cf1;
608 C<float> *cf2;
610 void f(C<int> a, C<float> b, C<double> c) {
611 auto p = a;
612 auto q = b;
613 auto r = c;
614 p.f(); // expected-error {{no member named 'f' in 'preferred_name::X'}}
615 q.f(); // expected-error {{no member named 'f' in 'preferred_name::Y'}}
616 r.f(); // expected-error {{no member named 'f' in 'preferred_name::C<double>'}}
619 template<typename T> struct D;
620 using DInt = D<int>;
621 template<typename T> struct __attribute__((__preferred_name__(DInt))) D {};
622 template struct D<int>;
623 int use_dint = D<int>().get(); // expected-error {{no member named 'get' in 'preferred_name::DInt'}}
625 template<typename T> struct MemberTemplate {
626 template<typename U> struct Iter;
627 using iterator = Iter<T>;
628 using const_iterator = Iter<const T>;
629 template<typename U>
630 struct [[clang::preferred_name(iterator),
631 clang::preferred_name(const_iterator)]] Iter {};
633 template<typename T> T desugar(T);
634 auto it = desugar(MemberTemplate<int>::Iter<const int>());
635 int n = it; // expected-error {{no viable conversion from 'preferred_name::MemberTemplate<int>::const_iterator' to 'int'}}
637 template<int A, int B, typename ...T> struct Foo;
638 template<typename ...T> using Bar = Foo<1, 2, T...>;
639 template<int A, int B, typename ...T> struct [[clang::preferred_name(::preferred_name::Bar<T...>)]] Foo {};
640 Foo<1, 2, int, float>::nosuch x; // expected-error {{no type named 'nosuch' in 'preferred_name::Bar<int, float>'}}
642 ::preferred_name::Foo<1, 2, int, float>::nosuch x; // expected-error {{no type named 'nosuch' in 'preferred_name::Bar<int, float>'}}