xref: /minix3/external/bsd/llvm/dist/clang/test/SemaTemplate/attributes.cpp (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1f4a2713aSLionel Sambuc // RUN: %clang_cc1 -std=gnu++11 -fsyntax-only -verify %s
2f4a2713aSLionel Sambuc 
3f4a2713aSLionel Sambuc namespace attribute_aligned {
4f4a2713aSLionel Sambuc   template<int N>
5f4a2713aSLionel Sambuc   struct X {
6f4a2713aSLionel Sambuc     char c[1] __attribute__((__aligned__((N)))); // expected-error {{alignment is not a power of 2}}
7f4a2713aSLionel Sambuc   };
8f4a2713aSLionel Sambuc 
9f4a2713aSLionel Sambuc   template <bool X> struct check {
10f4a2713aSLionel Sambuc     int check_failed[X ? 1 : -1]; // expected-error {{array with a negative size}}
11f4a2713aSLionel Sambuc   };
12f4a2713aSLionel Sambuc 
13f4a2713aSLionel Sambuc   template <int N> struct check_alignment {
14f4a2713aSLionel Sambuc     typedef check<N == sizeof(X<N>)> t; // expected-note {{in instantiation}}
15f4a2713aSLionel Sambuc   };
16f4a2713aSLionel Sambuc 
17f4a2713aSLionel Sambuc   check_alignment<1>::t c1;
18f4a2713aSLionel Sambuc   check_alignment<2>::t c2;
19f4a2713aSLionel Sambuc   check_alignment<3>::t c3; // expected-note 2 {{in instantiation}}
20f4a2713aSLionel Sambuc   check_alignment<4>::t c4;
21f4a2713aSLionel Sambuc 
22f4a2713aSLionel Sambuc   template<unsigned Size, unsigned Align>
23f4a2713aSLionel Sambuc   class my_aligned_storage
24f4a2713aSLionel Sambuc   {
25*0a6a1f1dSLionel Sambuc     __attribute__((aligned(Align))) char storage[Size];
26f4a2713aSLionel Sambuc   };
27f4a2713aSLionel Sambuc 
28f4a2713aSLionel Sambuc   template<typename T>
29f4a2713aSLionel Sambuc   class C {
30f4a2713aSLionel Sambuc   public:
C()31f4a2713aSLionel Sambuc     C() {
32f4a2713aSLionel Sambuc       static_assert(sizeof(t) == sizeof(T), "my_aligned_storage size wrong");
33f4a2713aSLionel Sambuc       static_assert(alignof(t) == alignof(T), "my_aligned_storage align wrong"); // expected-warning{{'alignof' applied to an expression is a GNU extension}}
34f4a2713aSLionel Sambuc     }
35f4a2713aSLionel Sambuc 
36f4a2713aSLionel Sambuc   private:
37f4a2713aSLionel Sambuc     my_aligned_storage<sizeof(T), alignof(T)> t;
38f4a2713aSLionel Sambuc   };
39f4a2713aSLionel Sambuc 
40f4a2713aSLionel Sambuc   C<double> cd;
41f4a2713aSLionel Sambuc }
42f4a2713aSLionel Sambuc 
43f4a2713aSLionel Sambuc namespace PR9049 {
44f4a2713aSLionel Sambuc   extern const void *CFRetain(const void *ref);
45f4a2713aSLionel Sambuc 
46f4a2713aSLionel Sambuc   template<typename T> __attribute__((cf_returns_retained))
WBCFRetain(T aValue)47f4a2713aSLionel Sambuc   inline T WBCFRetain(T aValue) { return aValue ? (T)CFRetain(aValue) : (T)0; }
48f4a2713aSLionel Sambuc 
49f4a2713aSLionel Sambuc 
50f4a2713aSLionel Sambuc   extern void CFRelease(const void *ref);
51f4a2713aSLionel Sambuc 
52f4a2713aSLionel Sambuc   template<typename T>
WBCFRelease(T aValue)53f4a2713aSLionel Sambuc   inline void WBCFRelease(__attribute__((cf_consumed)) T aValue) { if(aValue) CFRelease(aValue); }
54f4a2713aSLionel Sambuc }
55