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
{
7 char c
[1] __attribute__((__aligned__((N
)))); // expected-error {{alignment is not a power of 2}}
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
];
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}}
38 my_aligned_storage
<sizeof(T
), alignof(T
)> t
;
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
);
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 {{.*}} HasPackAnnotations
69 // CHECK-NEXT: NonTypeTemplateParmDecl {{.*}} referenced 'int' depth 0 index 0 ... Is
70 // CHECK-NEXT: FunctionDecl {{.*}} HasPackAnnotations 'void ()'
71 // CHECK-NEXT: AnnotateAttr {{.*}} "ANNOTATE_BAZ"
72 // CHECK-NEXT: PackExpansionExpr {{.*}} '<dependent type>'
73 // CHECK-NEXT: DeclRefExpr {{.*}} 'int' NonTypeTemplateParm {{.*}} 'Is' 'int'
74 // CHECK-NEXT: FunctionDecl {{.*}} used HasPackAnnotations 'void ()'
75 // CHECK-NEXT: TemplateArgument{{.*}} pack
76 // CHECK-NEXT: TemplateArgument{{.*}} integral 1
77 // CHECK-NEXT: TemplateArgument{{.*}} integral 2
78 // CHECK-NEXT: TemplateArgument{{.*}} integral 3
79 // CHECK-NEXT: AnnotateAttr {{.*}} "ANNOTATE_BAZ"
80 // CHECK-NEXT: ConstantExpr {{.*}} 'int'
81 // CHECK-NEXT: value: Int 1
82 // CHECK-NEXT: SubstNonTypeTemplateParmExpr {{.*}} 'int'
83 // CHECK-NEXT: NonTypeTemplateParmDecl {{.*}} referenced 'int' depth 0 index 0 ... Is
84 // CHECK-NEXT: IntegerLiteral {{.*}} 'int' 1
85 // CHECK-NEXT: ConstantExpr {{.*}} 'int'
86 // CHECK-NEXT: value: Int 2
87 // CHECK-NEXT: SubstNonTypeTemplateParmExpr {{.*}} 'int'
88 // CHECK-NEXT: NonTypeTemplateParmDecl {{.*}} referenced 'int' depth 0 index 0 ... Is
89 // CHECK-NEXT: IntegerLiteral {{.*}} 'int' 2
90 // CHECK-NEXT: ConstantExpr {{.*}} 'int'
91 // CHECK-NEXT: value: Int 3
92 // CHECK-NEXT: SubstNonTypeTemplateParmExpr {{.*}} 'int'
93 // CHECK-NEXT: NonTypeTemplateParmDecl {{.*}} referenced 'int' depth 0 index 0 ... Is
94 // CHECK-NEXT: IntegerLiteral {{.*}} 'int' 3
95 template <int... Is
> [[clang::annotate("ANNOTATE_BAZ", Is
...)]] void HasPackAnnotations();
96 void UsePackAnnotations() { HasPackAnnotations
<1, 2, 3>(); }
98 template <int... Is
> [[clang::annotate(Is
...)]] void HasOnlyPackAnnotation() {} // expected-error {{expected string literal as argument of 'annotate' attribute}}
100 void UseOnlyPackAnnotations() {
101 HasOnlyPackAnnotation
<>();
102 HasOnlyPackAnnotation
<1>();
105 // CHECK: ClassTemplateDecl {{.*}} AnnotatedPackTemplateStruct
106 // CHECK-NEXT: TemplateTypeParmDecl {{.*}} typename depth 0 index 0 T
107 // CHECK-NEXT: NonTypeTemplateParmDecl {{.*}} referenced 'int' depth 0 index 1 ... Is
108 // CHECK-NEXT: CXXRecordDecl {{.*}} struct AnnotatedPackTemplateStruct definition
109 // CHECK-NEXT: DefinitionData
110 // CHECK-NEXT: DefaultConstructor
111 // CHECK-NEXT: CopyConstructor
112 // CHECK-NEXT: MoveConstructor
113 // CHECK-NEXT: CopyAssignment
114 // CHECK-NEXT: MoveAssignment
115 // CHECK-NEXT: Destructor
116 // CHECK-NEXT: AnnotateAttr {{.*}} "ANNOTATE_FOZ"
117 // CHECK-NEXT: PackExpansionExpr {{.*}} '<dependent type>'
118 // CHECK-NEXT: DeclRefExpr {{.*}} 'int' NonTypeTemplateParm {{.*}} 'Is' 'int'
119 // CHECK-NEXT: CXXRecordDecl {{.*}} implicit struct AnnotatedPackTemplateStruct
120 // CHECK-NEXT: ClassTemplateSpecializationDecl {{.*}} struct AnnotatedPackTemplateStruct definition
121 // CHECK-NEXT: DefinitionData
122 // CHECK-NEXT: DefaultConstructor
123 // CHECK-NEXT: CopyConstructor
124 // CHECK-NEXT: MoveConstructor
125 // CHECK-NEXT: CopyAssignment
126 // CHECK-NEXT: MoveAssignment
127 // CHECK-NEXT: Destructor
128 // CHECK-NEXT: TemplateArgument{{.*}} type 'int'
129 // CHECK-NEXT: BuiltinType {{.*}} 'int'
130 // CHECK-NEXT: TemplateArgument{{.*}} pack
131 // CHECK-NEXT: TemplateArgument{{.*}} integral 1
132 // CHECK-NEXT: TemplateArgument{{.*}} integral 2
133 // CHECK-NEXT: TemplateArgument{{.*}} integral 3
134 // CHECK-NEXT: AnnotateAttr {{.*}} "ANNOTATE_BOO"
135 // CHECK-NEXT: ConstantExpr {{.*}} 'int'
136 // CHECK-NEXT: value: Int 1
137 // CHECK-NEXT: SubstNonTypeTemplateParmExpr {{.*}} 'int'
138 // CHECK-NEXT: NonTypeTemplateParmDecl {{.*}} referenced 'int' depth 0 index 0 ... Is
139 // CHECK-NEXT: IntegerLiteral {{.*}} 'int' 1
140 // CHECK-NEXT: ConstantExpr {{.*}} 'int'
141 // CHECK-NEXT: value: Int 2
142 // CHECK-NEXT: SubstNonTypeTemplateParmExpr {{.*}} 'int'
143 // CHECK-NEXT: NonTypeTemplateParmDecl {{.*}} referenced 'int' depth 0 index 0 ... Is
144 // CHECK-NEXT: IntegerLiteral {{.*}} 'int' 2
145 // CHECK-NEXT: ConstantExpr {{.*}} 'int'
146 // CHECK-NEXT: value: Int 3
147 // CHECK-NEXT: SubstNonTypeTemplateParmExpr {{.*}} 'int'
148 // CHECK-NEXT: NonTypeTemplateParmDecl {{.*}} referenced 'int' depth 0 index 0 ... Is
149 // CHECK-NEXT: IntegerLiteral {{.*}} 'int' 3
150 // CHECK-NEXT: CXXRecordDecl {{.*}} implicit struct AnnotatedPackTemplateStruct
151 // CHECK-NEXT: ClassTemplateSpecializationDecl {{.*}} struct AnnotatedPackTemplateStruct definition
152 // CHECK-NEXT: DefinitionData
153 // CHECK-NEXT: DefaultConstructor
154 // CHECK-NEXT: CopyConstructor
155 // CHECK-NEXT: MoveConstructor
156 // CHECK-NEXT: CopyAssignment
157 // CHECK-NEXT: MoveAssignment
158 // CHECK-NEXT: Destructor
159 // CHECK-NEXT: TemplateArgument type 'float'
160 // CHECK-NEXT: BuiltinType {{.*}} 'float'
161 // CHECK-NEXT: TemplateArgument{{.*}} pack
162 // CHECK-NEXT: TemplateArgument{{.*}} integral 3
163 // CHECK-NEXT: TemplateArgument{{.*}} integral 2
164 // CHECK-NEXT: TemplateArgument{{.*}} integral 1
165 // CHECK-NEXT: AnnotateAttr {{.*}} "ANNOTATE_FOZ"
166 // CHECK-NEXT: ConstantExpr {{.*}} 'int'
167 // CHECK-NEXT: value: Int 4
168 // CHECK-NEXT: IntegerLiteral {{.*}} 'int' 4
169 // CHECK-NEXT: ConstantExpr {{.*}} 'int'
170 // CHECK-NEXT: value: Int 5
171 // CHECK-NEXT: IntegerLiteral {{.*}} 'int' 5
172 // CHECK-NEXT: ConstantExpr {{.*}} 'int'
173 // CHECK-NEXT: value: Int 6
174 // CHECK-NEXT: IntegerLiteral {{.*}} 'int' 6
175 // CHECK-NEXT: CXXRecordDecl {{.*}} implicit struct AnnotatedPackTemplateStruct
176 // CHECK-NEXT: ClassTemplateSpecializationDecl {{.*}} struct AnnotatedPackTemplateStruct definition
177 // CHECK-NEXT: DefinitionData
178 // CHECK-NEXT: DefaultConstructor
179 // CHECK-NEXT: CopyConstructor
180 // CHECK-NEXT: MoveConstructor
181 // CHECK-NEXT: CopyAssignment
182 // CHECK-NEXT: MoveAssignment
183 // CHECK-NEXT: Destructor
184 // CHECK-NEXT: TemplateArgument type 'bool'
185 // CHECK-NEXT: BuiltinType {{.*}} 'bool'
186 // CHECK-NEXT: TemplateArgument{{.*}} pack
187 // CHECK-NEXT: TemplateArgument{{.*}} integral 7
188 // CHECK-NEXT: TemplateArgument{{.*}} integral 8
189 // CHECK-NEXT: TemplateArgument{{.*}} integral 9
190 // CHECK-NEXT: AnnotateAttr {{.*}} "ANNOTATE_FOZ"
191 // CHECK-NEXT: ConstantExpr {{.*}} 'int'
192 // CHECK-NEXT: value: Int 7
193 // CHECK-NEXT: SubstNonTypeTemplateParmExpr {{.*}} 'int'
194 // CHECK-NEXT: NonTypeTemplateParmDecl {{.*}} referenced 'int' depth 0 index 1 ... Is
195 // CHECK-NEXT: IntegerLiteral {{.*}} 'int' 7
196 // CHECK-NEXT: ConstantExpr {{.*}} 'int'
197 // CHECK-NEXT: value: Int 8
198 // CHECK-NEXT: SubstNonTypeTemplateParmExpr {{.*}} 'int'
199 // CHECK-NEXT: NonTypeTemplateParmDecl {{.*}} referenced 'int' depth 0 index 1 ... Is
200 // CHECK-NEXT: IntegerLiteral {{.*}} 'int' 8
201 // CHECK-NEXT: ConstantExpr {{.*}} 'int'
202 // CHECK-NEXT: value: Int 9
203 // CHECK-NEXT: SubstNonTypeTemplateParmExpr {{.*}} 'int'
204 // CHECK-NEXT: NonTypeTemplateParmDecl {{.*}} referenced 'int' depth 0 index 1 ... Is
205 // CHECK-NEXT: IntegerLiteral {{.*}} 'int' 9
206 // CHECK-NEXT: CXXRecordDecl {{.*}} implicit struct AnnotatedPackTemplateStruct
207 // CHECK-NEXT: ClassTemplateSpecializationDecl {{.*}} struct AnnotatedPackTemplateStruct definition
208 // CHECK-NEXT: DefinitionData
209 // CHECK-NEXT: DefaultConstructor
210 // CHECK-NEXT: CopyConstructor
211 // CHECK-NEXT: MoveConstructor
212 // CHECK-NEXT: CopyAssignment
213 // CHECK-NEXT: MoveAssignment
214 // CHECK-NEXT: Destructor
215 // CHECK-NEXT: TemplateArgument type 'char'
216 // CHECK-NEXT: BuiltinType {{.*}} 'char'
217 // CHECK-NEXT: TemplateArgument{{.*}} pack
218 // CHECK-NEXT: TemplateArgument{{.*}} integral 1
219 // CHECK-NEXT: TemplateArgument{{.*}} integral 2
220 // CHECK-NEXT: TemplateArgument{{.*}} integral 3
221 // CHECK-NEXT: CXXRecordDecl {{.*}} implicit struct AnnotatedPackTemplateStruct
222 // CHECK-NEXT: ClassTemplateSpecializationDecl {{.*}} struct AnnotatedPackTemplateStruct definition
223 // CHECK-NEXT: DefinitionData
224 // CHECK-NEXT: DefaultConstructor
225 // CHECK-NEXT: CopyConstructor
226 // CHECK-NEXT: MoveConstructor
227 // CHECK-NEXT: CopyAssignment
228 // CHECK-NEXT: MoveAssignment
229 // CHECK-NEXT: Destructor
230 // CHECK-NEXT: TemplateArgument{{.*}} type 'char'
231 // CHECK-NEXT: BuiltinType {{.*}} 'char'
232 // CHECK-NEXT: TemplateArgument{{.*}} pack
233 // CHECK-NEXT: CXXRecordDecl {{.*}} implicit struct AnnotatedPackTemplateStruct
234 // CHECK-NEXT: ClassTemplatePartialSpecializationDecl {{.*}} struct AnnotatedPackTemplateStruct definition
235 // CHECK-NEXT: DefinitionData
236 // CHECK-NEXT: DefaultConstructor
237 // CHECK-NEXT: CopyConstructor
238 // CHECK-NEXT: MoveConstructor
239 // CHECK-NEXT: CopyAssignment
240 // CHECK-NEXT: MoveAssignment
241 // CHECK-NEXT: Destructor
242 // CHECK-NEXT: TemplateArgument{{.*}} type 'int'
243 // CHECK-NEXT: BuiltinType {{.*}} 'int'
244 // CHECK-NEXT: TemplateArgument{{.*}} pack
245 // CHECK-NEXT: TemplateArgument{{.*}} expr
246 // CHECK-NEXT: PackExpansionExpr {{.*}} 'int'
247 // CHECK-NEXT: DeclRefExpr {{.*}} 'int' NonTypeTemplateParm {{.*}} 'Is' 'int'
248 // CHECK-NEXT: NonTypeTemplateParmDecl {{.*}} referenced 'int' depth 0 index 0 ... Is
249 // CHECK-NEXT: AnnotateAttr {{.*}} "ANNOTATE_BOO"
250 // CHECK-NEXT: PackExpansionExpr {{.*}} '<dependent type>'
251 // CHECK-NEXT: DeclRefExpr {{.*}} 'int' NonTypeTemplateParm {{.*}} 'Is' 'int'
252 // CHECK-NEXT: CXXRecordDecl {{.*}} implicit struct AnnotatedPackTemplateStruct
253 // CHECK-NEXT: ClassTemplatePartialSpecializationDecl {{.*}} struct AnnotatedPackTemplateStruct definition
254 // CHECK-NEXT: DefinitionData
255 // CHECK-NEXT: DefaultConstructor
256 // CHECK-NEXT: CopyConstructor
257 // CHECK-NEXT: MoveConstructor
258 // CHECK-NEXT: CopyAssignment
259 // CHECK-NEXT: MoveAssignment
260 // CHECK-NEXT: Destructor
261 // CHECK-NEXT: TemplateArgument{{.*}} type 'float'
262 // CHECK-NEXT: BuiltinType {{.*}} 'float'
263 // CHECK-NEXT: TemplateArgument{{.*}} pack
264 // CHECK-NEXT: TemplateArgument{{.*}} expr
265 // CHECK-NEXT: PackExpansionExpr {{.*}} 'int'
266 // CHECK-NEXT: DeclRefExpr {{.*}} 'int' NonTypeTemplateParm {{.*}} 'Is' 'int'
267 // CHECK-NEXT: NonTypeTemplateParmDecl {{.*}} referenced 'int' depth 0 index 0 ... Is
268 // CHECK-NEXT: AnnotateAttr {{.*}} "ANNOTATE_FOZ"
269 // CHECK-NEXT: ConstantExpr {{.*}} 'int'
270 // CHECK-NEXT: value: Int 4
271 // CHECK-NEXT: IntegerLiteral {{.*}} 'int' 4
272 // CHECK-NEXT: ConstantExpr {{.*}} 'int'
273 // CHECK-NEXT: value: Int 5
274 // CHECK-NEXT: IntegerLiteral {{.*}} 'int' 5
275 // CHECK-NEXT: ConstantExpr {{.*}} 'int'
276 // CHECK-NEXT: value: Int 6
277 // CHECK-NEXT: IntegerLiteral {{.*}} 'int' 6
278 // CHECK-NEXT: CXXRecordDecl {{.*}} implicit struct AnnotatedPackTemplateStruct
279 template <typename T
, int... Is
> struct [[clang::annotate("ANNOTATE_FOZ", Is
...)]] AnnotatedPackTemplateStruct
{};
280 template <int... Is
> struct [[clang::annotate("ANNOTATE_BOO", Is
...)]] AnnotatedPackTemplateStruct
<int, Is
...>{};
281 template <int... Is
> struct [[clang::annotate("ANNOTATE_FOZ", 4, 5, 6)]] AnnotatedPackTemplateStruct
<float, Is
...>{};
282 template <int... Is
> struct [[clang::annotate(Is
...)]] AnnotatedPackTemplateStruct
<char, Is
...>{}; // expected-error {{expected string literal as argument of 'annotate' attribute}}
283 void UseAnnotatedPackTemplateStructSpecializations() {
284 AnnotatedPackTemplateStruct
<int, 1, 2, 3> Instance1
{};
285 AnnotatedPackTemplateStruct
<float, 3, 2, 1> Instance2
{};
286 AnnotatedPackTemplateStruct
<bool, 7, 8, 9> Instance3
{};
287 AnnotatedPackTemplateStruct
<char, 1, 2, 3> Instance4
{};
288 AnnotatedPackTemplateStruct
<char> Instance5
{};
291 // CHECK: ClassTemplateDecl {{.*}} InvalidAnnotatedPackTemplateStruct
292 // CHECK-NEXT: TemplateTypeParmDecl {{.*}} typename depth 0 index 0 T
293 // CHECK-NEXT: NonTypeTemplateParmDecl {{.*}} 'int' depth 0 index 1 ... Is
294 // CHECK-NEXT: CXXRecordDecl {{.*}} struct InvalidAnnotatedPackTemplateStruct definition
295 // CHECK-NEXT: DefinitionData
296 // CHECK-NEXT: DefaultConstructor
297 // CHECK-NEXT: CopyConstructor
298 // CHECK-NEXT: MoveConstructor
299 // CHECK-NEXT: CopyAssignment
300 // CHECK-NEXT: MoveAssignment
301 // CHECK-NEXT: Destructor
302 // CHECK-NEXT: CXXRecordDecl {{.*}} implicit struct InvalidAnnotatedPackTemplateStruct
303 // CHECK-NEXT: ClassTemplateSpecialization {{.*}} 'InvalidAnnotatedPackTemplateStruct'
304 // CHECK-NEXT: ClassTemplateSpecializationDecl {{.*}} struct InvalidAnnotatedPackTemplateStruct definition
305 // CHECK-NEXT: DefinitionData
306 // CHECK-NEXT: DefaultConstructor
307 // CHECK-NEXT: CopyConstructor
308 // CHECK-NEXT: MoveConstructor
309 // CHECK-NEXT: CopyAssignment
310 // CHECK-NEXT: MoveAssignment
311 // CHECK-NEXT: Destructor
312 // CHECK-NEXT: TemplateArgument{{.*}} type 'int'
313 // CHECK-NEXT: BuiltinType {{.*}} 'int'
314 // CHECK-NEXT: TemplateArgument{{.*}} pack
315 // CHECK-NEXT: TemplateArgument{{.*}} integral 1
316 // CHECK-NEXT: TemplateArgument{{.*}} integral 2
317 // CHECK-NEXT: TemplateArgument{{.*}} integral 3
318 // CHECK-NEXT: AnnotateAttr {{.*}} "ANNOTATE_BIR"
319 // CHECK-NEXT: ConstantExpr {{.*}} 'int'
320 // CHECK-NEXT: value: Int 1
321 // CHECK-NEXT: SubstNonTypeTemplateParmExpr {{.*}} 'int'
322 // CHECK-NEXT: NonTypeTemplateParmDecl {{.*}} referenced 'int' depth 0 index 0 ... Is
323 // CHECK-NEXT: IntegerLiteral {{.*}} 'int' 1
324 // CHECK-NEXT: ConstantExpr {{.*}} 'int'
325 // CHECK-NEXT: value: Int 2
326 // CHECK-NEXT: SubstNonTypeTemplateParmExpr {{.*}} 'int'
327 // CHECK-NEXT: NonTypeTemplateParmDecl {{.*}} referenced 'int' depth 0 index 0 ... Is
328 // CHECK-NEXT: IntegerLiteral {{.*}} 'int' 2
329 // CHECK-NEXT: ConstantExpr {{.*}} 'int'
330 // CHECK-NEXT: value: Int 3
331 // CHECK-NEXT: SubstNonTypeTemplateParmExpr {{.*}} 'int'
332 // CHECK-NEXT: NonTypeTemplateParmDecl {{.*}} referenced 'int' depth 0 index 0 ... Is
333 // CHECK-NEXT: IntegerLiteral {{.*}} 'int' 3
334 // CHECK-NEXT: CXXRecordDecl {{.*}} implicit struct InvalidAnnotatedPackTemplateStruct
335 // CHECK-NEXT: ClassTemplateSpecializationDecl {{.*}} struct InvalidAnnotatedPackTemplateStruct definition
336 // CHECK-NEXT: DefinitionData
337 // CHECK-NEXT: DefaultConstructor
338 // CHECK-NEXT: CopyConstructor
339 // CHECK-NEXT: MoveConstructor
340 // CHECK-NEXT: CopyAssignment
341 // CHECK-NEXT: MoveAssignment
342 // CHECK-NEXT: Destructor
343 // CHECK-NEXT: TemplateArgument{{.*}} type 'float'
344 // CHECK-NEXT: BuiltinType {{.*}} 'float'
345 // CHECK-NEXT: TemplateArgument{{.*}} pack
346 // CHECK-NEXT: TemplateArgument{{.*}} integral 3
347 // CHECK-NEXT: TemplateArgument{{.*}} integral 2
348 // CHECK-NEXT: TemplateArgument{{.*}} integral 1
349 // CHECK-NEXT: CXXRecordDecl {{.*}} implicit struct InvalidAnnotatedPackTemplateStruct
350 // CHECK-NEXT: ClassTemplateSpecializationDecl {{.*}} struct InvalidAnnotatedPackTemplateStruct definition
351 // CHECK-NEXT: DefinitionData
352 // CHECK-NEXT: DefaultConstructor
353 // CHECK-NEXT: CopyConstructor
354 // CHECK-NEXT: MoveConstructor
355 // CHECK-NEXT: CopyAssignment
356 // CHECK-NEXT: MoveAssignment
357 // CHECK-NEXT: Destructor
358 // CHECK-NEXT: TemplateArgument{{.*}} type 'bool'
359 // CHECK-NEXT: BuiltinType {{.*}} 'bool'
360 // CHECK-NEXT: TemplateArgument{{.*}} pack
361 // CHECK-NEXT: TemplateArgument{{.*}} integral 7
362 // CHECK-NEXT: TemplateArgument{{.*}} integral 8
363 // CHECK-NEXT: TemplateArgument{{.*}} integral 9
364 // CHECK-NEXT: CXXRecordDecl {{.*}} implicit struct InvalidAnnotatedPackTemplateStruct
365 // CHECK-NEXT: ClassTemplateSpecializationDecl {{.*}} struct InvalidAnnotatedPackTemplateStruct definition
366 // CHECK-NEXT: DefinitionData
367 // CHECK-NEXT: DefaultConstructor
368 // CHECK-NEXT: CopyConstructor
369 // CHECK-NEXT: MoveConstructor
370 // CHECK-NEXT: CopyAssignment
371 // CHECK-NEXT: MoveAssignment
372 // CHECK-NEXT: Destructor
373 // CHECK-NEXT: TemplateArgument{{.*}} type 'bool'
374 // CHECK-NEXT: BuiltinType {{.*}} 'bool'
375 // CHECK-NEXT: TemplateArgument{{.*}} pack
376 // CHECK-NEXT: CXXRecordDecl {{.*}} implicit struct InvalidAnnotatedPackTemplateStruct
377 // CHECK-NEXT: ClassTemplatePartialSpecializationDecl {{.*}} struct InvalidAnnotatedPackTemplateStruct definition
378 // CHECK-NEXT: DefinitionData
379 // CHECK-NEXT: DefaultConstructor
380 // CHECK-NEXT: CopyConstructor
381 // CHECK-NEXT: MoveConstructor
382 // CHECK-NEXT: CopyAssignment
383 // CHECK-NEXT: MoveAssignment
384 // CHECK-NEXT: Destructor
385 // CHECK-NEXT: TemplateArgument{{.*}} type 'int'
386 // CHECK-NEXT: BuiltinType {{.*}} 'int'
387 // CHECK-NEXT: TemplateArgument{{.*}} pack
388 // CHECK-NEXT: TemplateArgument{{.*}} expr
389 // CHECK-NEXT: PackExpansionExpr {{.*}} 'int'
390 // CHECK-NEXT: DeclRefExpr {{.*}} 'int' NonTypeTemplateParm {{.*}} 'Is' 'int'
391 // CHECK-NEXT: NonTypeTemplateParmDecl {{.*}} referenced 'int' depth 0 index 0 ... Is
392 // CHECK-NEXT: AnnotateAttr {{.*}} "ANNOTATE_BIR"
393 // CHECK-NEXT: PackExpansionExpr {{.*}} '<dependent type>'
394 // CHECK-NEXT: DeclRefExpr {{.*}} 'int' NonTypeTemplateParm {{.*}} 'Is' 'int'
395 // CHECK-NEXT: CXXRecordDecl {{.*}} implicit struct InvalidAnnotatedPackTemplateStruct
396 // CHECK-NEXT: ClassTemplatePartialSpecializationDecl {{.*}} struct InvalidAnnotatedPackTemplateStruct definition
397 // CHECK-NEXT: DefinitionData
398 // CHECK-NEXT: DefaultConstructor
399 // CHECK-NEXT: CopyConstructor
400 // CHECK-NEXT: MoveConstructor
401 // CHECK-NEXT: CopyAssignment
402 // CHECK-NEXT: MoveAssignment
403 // CHECK-NEXT: Destructor
404 // CHECK-NEXT: TemplateArgument{{.*}} type 'float'
405 // CHECK-NEXT: BuiltinType {{.*}} 'float'
406 // CHECK-NEXT: TemplateArgument{{.*}} pack
407 // CHECK-NEXT: TemplateArgument{{.*}} expr
408 // CHECK-NEXT: PackExpansionExpr {{.*}} 'int'
409 // CHECK-NEXT: DeclRefExpr {{.*}} 'int' NonTypeTemplateParm {{.*}} 'Is' 'int'
410 // CHECK-NEXT: NonTypeTemplateParmDecl {{.*}} referenced 'int' depth 0 index 0 ... Is
411 // CHECK-NEXT: CXXRecordDecl {{.*}} implicit struct InvalidAnnotatedPackTemplateStruct
412 // CHECK-NEXT: ClassTemplateSpecializationDecl {{.*}} struct InvalidAnnotatedPackTemplateStruct definition
413 // CHECK-NEXT: DefinitionData
414 // CHECK-NEXT: DefaultConstructor
415 // CHECK-NEXT: CopyConstructor
416 // CHECK-NEXT: MoveConstructor
417 // CHECK-NEXT: CopyAssignment
418 // CHECK-NEXT: MoveAssignment
419 // CHECK-NEXT: Destructor
420 // CHECK-NEXT: TemplateArgument{{.*}} type 'char'
421 // CHECK-NEXT: BuiltinType {{.*}} 'char'
422 // CHECK-NEXT: TemplateArgument{{.*}} pack
423 // CHECK-NEXT: TemplateArgument{{.*}} integral 5
424 // CHECK-NEXT: TemplateArgument{{.*}} integral 6
425 // CHECK-NEXT: TemplateArgument{{.*}} integral 7
426 // CHECK-NEXT: CXXRecordDecl {{.*}} implicit struct InvalidAnnotatedPackTemplateStruct
427 template <typename T
, int... Is
> struct InvalidAnnotatedPackTemplateStruct
{};
428 template <int... Is
> struct [[clang::annotate("ANNOTATE_BIR", Is
...)]] InvalidAnnotatedPackTemplateStruct
<int, Is
...>{};
429 template <int... Is
> struct InvalidAnnotatedPackTemplateStruct
<float, Is
...> {};
430 template <> struct InvalidAnnotatedPackTemplateStruct
<char, 5, 6, 7> {};
431 void UseInvalidAnnotatedPackTemplateStruct() {
432 InvalidAnnotatedPackTemplateStruct
<int, 1, 2, 3> Instance1
{};
433 InvalidAnnotatedPackTemplateStruct
<float, 3, 2, 1> Instance2
{};
434 InvalidAnnotatedPackTemplateStruct
<char, 5, 6, 7> Instance3
{};
435 InvalidAnnotatedPackTemplateStruct
<bool, 7, 8, 9> Instance4
{};
436 InvalidAnnotatedPackTemplateStruct
<bool> Instance5
{};
439 // CHECK: FunctionTemplateDecl {{.*}} RedeclaredAnnotatedFunc
440 // CHECK-NEXT: NonTypeTemplateParmDecl {{.*}} referenced 'int' depth 0 index 0 ... Is
441 // CHECK-NEXT: FunctionDecl {{.*}} RedeclaredAnnotatedFunc 'void ()'
442 // CHECK-NEXT: AnnotateAttr {{.*}} "ANNOTATE_FAR"
443 // CHECK-NEXT: PackExpansionExpr {{.*}} '<dependent type>'
444 // CHECK-NEXT: DeclRefExpr {{.*}} 'int' NonTypeTemplateParm {{.*}} 'Is' 'int'
445 // CHECK-NEXT: FunctionDecl {{.*}} used RedeclaredAnnotatedFunc 'void ()'
446 // CHECK-NEXT: TemplateArgument{{.*}} pack
447 // CHECK-NEXT: TemplateArgument{{.*}} integral 1
448 // CHECK-NEXT: TemplateArgument{{.*}} integral 2
449 // CHECK-NEXT: TemplateArgument{{.*}} integral 3
450 // CHECK-NEXT: CompoundStmt
451 // CHECK-NEXT: AnnotateAttr {{.*}} "ANNOTATE_FAR"
452 // CHECK-NEXT: ConstantExpr {{.*}} 'int'
453 // CHECK-NEXT: value: Int 1
454 // CHECK-NEXT: SubstNonTypeTemplateParmExpr {{.*}} 'int'
455 // CHECK-NEXT: NonTypeTemplateParmDecl {{.*}} referenced 'int' depth 0 index 0 ... Is
456 // CHECK-NEXT: IntegerLiteral {{.*}} 'int' 1
457 // CHECK-NEXT: ConstantExpr {{.*}} 'int'
458 // CHECK-NEXT: value: Int 2
459 // CHECK-NEXT: SubstNonTypeTemplateParmExpr {{.*}} 'int'
460 // CHECK-NEXT: NonTypeTemplateParmDecl {{.*}} referenced 'int' depth 0 index 0 ... Is
461 // CHECK-NEXT: IntegerLiteral {{.*}} 'int' 2
462 // CHECK-NEXT: ConstantExpr {{.*}} 'int'
463 // CHECK-NEXT: value: Int 3
464 // CHECK-NEXT: SubstNonTypeTemplateParmExpr {{.*}} 'int'
465 // CHECK-NEXT: NonTypeTemplateParmDecl {{.*}} referenced 'int' depth 0 index 0 ... Is
466 // CHECK-NEXT: IntegerLiteral {{.*}} 'int' 3
467 // CHECK-NEXT: AnnotateAttr {{.*}} "ANNOTATE_FIZ"
468 // CHECK-NEXT: ConstantExpr {{.*}} 'int'
469 // CHECK-NEXT: value: Int 4
470 // CHECK-NEXT: IntegerLiteral {{.*}} 'int' 4
471 // CHECK-NEXT: ConstantExpr {{.*}} 'int'
472 // CHECK-NEXT: value: Int 5
473 // CHECK-NEXT: IntegerLiteral {{.*}} 'int' 5
474 // CHECK-NEXT: AnnotateAttr {{.*}} "ANNOTATE_BOZ"
475 // CHECK-NEXT: ConstantExpr {{.*}} 'int'
476 // CHECK-NEXT: value: Int 6
477 // CHECK-NEXT: IntegerLiteral {{.*}} 'int' 6
478 // CHECK-NEXT: FunctionTemplateDecl {{.*}} prev {{.*}} RedeclaredAnnotatedFunc
479 // CHECK-NEXT: NonTypeTemplateParmDecl {{.*}} referenced 'int' depth 0 index 0 ... Is
480 // CHECK-NEXT: FunctionDecl {{.*}} prev {{.*}} RedeclaredAnnotatedFunc 'void ()'
481 // CHECK-NEXT: AnnotateAttr {{.*}} Inherited "ANNOTATE_FAR"
482 // CHECK-NEXT: PackExpansionExpr {{.*}} '<dependent type>'
483 // CHECK-NEXT: DeclRefExpr {{.*}} 'int' NonTypeTemplateParm {{.*}} 'Is' 'int'
484 // CHECK-NEXT: AnnotateAttr {{.*}} "ANNOTATE_BOZ"
485 // CHECK-NEXT: PackExpansionExpr {{.*}} '<dependent type>'
486 // CHECK-NEXT: DeclRefExpr {{.*}} 'int' NonTypeTemplateParm {{.*}} 'Is' 'int'
487 // CHECK-NEXT: Function {{.*}} 'RedeclaredAnnotatedFunc' 'void ()'
488 // CHECK-NEXT: FunctionTemplateDecl {{.*}} prev {{.*}} RedeclaredAnnotatedFunc
489 // CHECK-NEXT: NonTypeTemplateParmDecl {{.*}} 'int' depth 0 index 0 ... Is
490 // CHECK-NEXT: FunctionDecl {{.*}} prev {{.*}} RedeclaredAnnotatedFunc 'void ()'
491 // CHECK-NEXT: AnnotateAttr {{.*}} Inherited "ANNOTATE_FAR"
492 // CHECK-NEXT: PackExpansionExpr {{.*}} '<dependent type>'
493 // CHECK-NEXT: DeclRefExpr {{.*}} 'int' NonTypeTemplateParm {{.*}} 'Is' 'int'
494 // CHECK-NEXT: AnnotateAttr {{.*}} Inherited "ANNOTATE_BOZ"
495 // CHECK-NEXT: PackExpansionExpr {{.*}} '<dependent type>'
496 // CHECK-NEXT: DeclRefExpr {{.*}} 'int' NonTypeTemplateParm {{.*}} 'Is' 'int'
497 // CHECK-NEXT: AnnotateAttr {{.*}} "ANNOTATE_FIZ"
498 // CHECK-NEXT: ConstantExpr {{.*}} 'int'
499 // CHECK-NEXT: value: Int 4
500 // CHECK-NEXT: IntegerLiteral {{.*}} 'int' 4
501 // CHECK-NEXT: ConstantExpr {{.*}} 'int'
502 // CHECK-NEXT: value: Int 5
503 // CHECK-NEXT: IntegerLiteral {{.*}} 'int' 5
504 // CHECK-NEXT: Function {{.*}} 'RedeclaredAnnotatedFunc' 'void ()'
505 // CHECK-NEXT: FunctionTemplateDecl {{.*}} prev {{.*}} RedeclaredAnnotatedFunc
506 // CHECK-NEXT: NonTypeTemplateParmDecl {{.*}} 'int' depth 0 index 0 ... Is
507 // CHECK-NEXT: FunctionDecl {{.*}} prev {{.*}} RedeclaredAnnotatedFunc 'void ()'
508 // CHECK-NEXT: CompoundStmt
509 // CHECK-NEXT: AnnotateAttr {{.*}} Inherited "ANNOTATE_FAR"
510 // CHECK-NEXT: PackExpansionExpr {{.*}} '<dependent type>'
511 // CHECK-NEXT: DeclRefExpr {{.*}} 'int' NonTypeTemplateParm {{.*}} 'Is' 'int'
512 // CHECK-NEXT: AnnotateAttr {{.*}} Inherited "ANNOTATE_FIZ"
513 // CHECK-NEXT: ConstantExpr {{.*}} 'int'
514 // CHECK-NEXT: value: Int 4
515 // CHECK-NEXT: IntegerLiteral {{.*}} 'int' 4
516 // CHECK-NEXT: ConstantExpr {{.*}} 'int'
517 // CHECK-NEXT: value: Int 5
518 // CHECK-NEXT: IntegerLiteral {{.*}} 'int' 5
519 // CHECK-NEXT: AnnotateAttr {{.*}} "ANNOTATE_BOZ"
520 // CHECK-NEXT: ConstantExpr {{.*}} 'int'
521 // CHECK-NEXT: value: Int 6
522 // CHECK-NEXT: IntegerLiteral {{.*}} 'int' 6
523 // CHECK-NEXT: Function {{.*}} 'RedeclaredAnnotatedFunc' 'void ()'
524 // CHECK-NEXT: EmptyDecl
525 template <int... Is
> [[clang::annotate("ANNOTATE_FAR", Is
...)]] void RedeclaredAnnotatedFunc();
526 template <int... Is
> [[clang::annotate("ANNOTATE_BOZ", Is
...)]] void RedeclaredAnnotatedFunc();
527 template <int... Is
> [[clang::annotate("ANNOTATE_FIZ", 4, 5)]] void RedeclaredAnnotatedFunc();
528 template <int... Is
> [[clang::annotate("ANNOTATE_BOZ", 6)]] void RedeclaredAnnotatedFunc(){};
529 void UseRedeclaredAnnotatedFunc() {
530 RedeclaredAnnotatedFunc
<1, 2, 3>();
533 } // namespace attribute_annotate
535 namespace preferred_name
{
536 int x
[[clang::preferred_name("frank")]]; // expected-error {{expected a type}}
537 int y
[[clang::preferred_name(int)]]; // expected-warning {{'preferred_name' attribute only applies to class templates}}
538 struct [[clang::preferred_name(int)]] A
; // expected-warning {{'preferred_name' attribute only applies to class templates}}
539 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'}}
540 template<typename T
> struct C
;
541 using X
= C
<int>; // expected-note {{'X' declared here}}
543 using Z
= const C
<double>; // expected-note {{'Z' declared here}}
544 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'}}
545 template<typename T
> struct [[clang::preferred_name(X
), clang::preferred_name(Y
)]] C
;
546 template<typename T
> struct [[clang::preferred_name(const X
)]] C
; // expected-error {{argument 'const X'}}
547 template<typename T
> struct [[clang::preferred_name(Z
)]] C
; // expected-error {{argument 'Z' (aka 'const C<double>')}}
548 template<typename T
> struct C
{};
550 // CHECK: ClassTemplateDecl {{.*}} <line:[[@LINE-10]]:{{.*}} C
551 // CHECK: ClassTemplateSpecializationDecl {{.*}} struct C definition
552 // CHECK: TemplateArgument type 'int'
553 // CHECK-NOT: PreferredNameAttr
554 // CHECK: PreferredNameAttr {{.*}} X
555 // CHECK-NOT: PreferredNameAttr
556 // CHECK: CXXRecordDecl
557 // CHECK: ClassTemplateSpecializationDecl {{.*}} struct C definition
558 // CHECK: TemplateArgument type 'float'
559 // CHECK-NOT: PreferredNameAttr
560 // CHECK: PreferredNameAttr {{.*}} Y
561 // CHECK-NOT: PreferredNameAttr
562 // CHECK: CXXRecordDecl
563 // CHECK: ClassTemplateSpecializationDecl {{.*}} struct C definition
564 // CHECK: TemplateArgument type 'double'
565 // CHECK-NOT: PreferredNameAttr
566 // CHECK: CXXRecordDecl
568 // Check this doesn't cause us to instantiate the same attribute multiple times.
572 void f(C
<int> a
, C
<float> b
, C
<double> c
) {
576 p
.f(); // expected-error {{no member named 'f' in 'preferred_name::X'}}
577 q
.f(); // expected-error {{no member named 'f' in 'preferred_name::Y'}}
578 r
.f(); // expected-error {{no member named 'f' in 'preferred_name::C<double>'}}
581 template<typename T
> struct D
;
583 template<typename T
> struct __attribute__((__preferred_name__(DInt
))) D
{};
584 template struct D
<int>;
585 int use_dint
= D
<int>().get(); // expected-error {{no member named 'get' in 'preferred_name::DInt'}}
587 template<typename T
> struct MemberTemplate
{
588 template<typename U
> struct Iter
;
589 using iterator
= Iter
<T
>;
590 using const_iterator
= Iter
<const T
>;
592 struct [[clang::preferred_name(iterator
),
593 clang::preferred_name(const_iterator
)]] Iter
{};
595 template<typename T
> T
desugar(T
);
596 auto it
= desugar(MemberTemplate
<int>::Iter
<const int>());
597 int n
= it
; // expected-error {{no viable conversion from 'preferred_name::MemberTemplate<int>::const_iterator' to 'int'}}
599 template<int A
, int B
, typename
...T
> struct Foo
;
600 template<typename
...T
> using Bar
= Foo
<1, 2, T
...>;
601 template<int A
, int B
, typename
...T
> struct [[clang::preferred_name(::preferred_name::Bar
<T
...>)]] Foo
{};
602 Foo
<1, 2, int, float>::nosuch x
; // expected-error {{no type named 'nosuch' in 'preferred_name::Bar<int, float>'}}
604 ::preferred_name::Foo
<1, 2, int, float>::nosuch x
; // expected-error {{no type named 'nosuch' in 'preferred_name::Bar<int, float>'}}