blob: 7634b937c906896c1b1829d3801bb902ba3a566d [file] [log] [blame]
Douglas Gregord2472d42013-05-02 23:25:32 +00001// RUN: %clang_cc1 -std=gnu++11 -fsyntax-only -verify %s
Richard Smith33bddbd2018-01-04 23:42:29 +00002// RUN: not %clang_cc1 -std=gnu++11 -ast-dump %s | FileCheck %s
Douglas Gregorbdb604a2010-05-18 23:01:22 +00003
Chandler Carruthf40c42f2010-06-25 03:22:07 +00004namespace 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 };
Douglas Gregorbdb604a2010-05-18 23:01:22 +00009
Chandler Carruthf40c42f2010-06-25 03:22:07 +000010 template <bool X> struct check {
Chandler Carrutha92409c2011-01-04 04:44:35 +000011 int check_failed[X ? 1 : -1]; // expected-error {{array with a negative size}}
Chandler Carruthf40c42f2010-06-25 03:22:07 +000012 };
13
14 template <int N> struct check_alignment {
15 typedef check<N == sizeof(X<N>)> t; // expected-note {{in instantiation}}
16 };
17
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;
Douglas Gregord2472d42013-05-02 23:25:32 +000022
23 template<unsigned Size, unsigned Align>
24 class my_aligned_storage
25 {
Aaron Ballman87e7dea2014-01-13 21:30:03 +000026 __attribute__((aligned(Align))) char storage[Size];
Douglas Gregord2472d42013-05-02 23:25:32 +000027 };
28
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}}
35 }
36
37 private:
38 my_aligned_storage<sizeof(T), alignof(T)> t;
39 };
40
41 C<double> cd;
Chandler Carruthf40c42f2010-06-25 03:22:07 +000042}
Douglas Gregorf892c7f2011-10-09 22:26:49 +000043
44namespace PR9049 {
45 extern const void *CFRetain(const void *ref);
46
47 template<typename T> __attribute__((cf_returns_retained))
48 inline T WBCFRetain(T aValue) { return aValue ? (T)CFRetain(aValue) : (T)0; }
49
50
51 extern void CFRelease(const void *ref);
52
53 template<typename T>
54 inline void WBCFRelease(__attribute__((cf_consumed)) T aValue) { if(aValue) CFRelease(aValue); }
55}
Richard Smith33bddbd2018-01-04 23:42:29 +000056
57// CHECK: FunctionTemplateDecl {{.*}} HasAnnotations
58// CHECK: AnnotateAttr {{.*}} "ANNOTATE_BAR"
59// CHECK: AnnotateAttr {{.*}} "ANNOTATE_FOO"
60// CHECK: FunctionDecl {{.*}} HasAnnotations
61// CHECK: TemplateArgument type 'int'
62// CHECK: AnnotateAttr {{.*}} "ANNOTATE_BAR"
63// CHECK: AnnotateAttr {{.*}} "ANNOTATE_FOO"
64template<typename T> [[clang::annotate("ANNOTATE_FOO"), clang::annotate("ANNOTATE_BAR")]] void HasAnnotations();
65void UseAnnotations() { HasAnnotations<int>(); }