Clang Project

clang_source_code/test/SemaTemplate/attributes.cpp
1// RUN: %clang_cc1 -std=gnu++11 -fsyntax-only -verify %s
2// RUN: not %clang_cc1 -std=gnu++11 -ast-dump %s | FileCheck %s
3
4namespace 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  };
9
10  template <bool X> struct check {
11    int check_failed[X ? 1 : -1]; // expected-error {{array with a negative size}}
12  };
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;
22
23  template<unsigned Size, unsigned Align>
24  class my_aligned_storage
25  {
26    __attribute__((aligned(Align))) char storage[Size];
27  };
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;
42}
43
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}
56
57// CHECK: FunctionTemplateDecl {{.*}} HasAnnotations
58// CHECK:   AnnotateAttr {{.*}} "ANNOTATE_FOO"
59// CHECK:   AnnotateAttr {{.*}} "ANNOTATE_BAR"
60// CHECK: FunctionDecl {{.*}} HasAnnotations
61// CHECK:   TemplateArgument type 'int'
62// CHECK:   AnnotateAttr {{.*}} "ANNOTATE_FOO"
63// CHECK:   AnnotateAttr {{.*}} "ANNOTATE_BAR"
64template<typename T> [[clang::annotate("ANNOTATE_FOO"), clang::annotate("ANNOTATE_BAR")]] void HasAnnotations();
65void UseAnnotations() { HasAnnotations<int>(); }
66