blob: 1d46058b0191adad300c2661a370af81db415e96 [file] [log] [blame]
Douglas Gregord2472d42013-05-02 23:25:32 +00001// RUN: %clang_cc1 -std=gnu++11 -fsyntax-only -verify %s
Douglas Gregorbdb604a2010-05-18 23:01:22 +00002
Chandler Carruthf40c42f2010-06-25 03:22:07 +00003namespace attribute_aligned {
4 template<int N>
5 struct X {
6 char c[1] __attribute__((__aligned__((N)))); // expected-error {{alignment is not a power of 2}}
7 };
Douglas Gregorbdb604a2010-05-18 23:01:22 +00008
Chandler Carruthf40c42f2010-06-25 03:22:07 +00009 template <bool X> struct check {
Chandler Carrutha92409c2011-01-04 04:44:35 +000010 int check_failed[X ? 1 : -1]; // expected-error {{array with a negative size}}
Chandler Carruthf40c42f2010-06-25 03:22:07 +000011 };
12
13 template <int N> struct check_alignment {
14 typedef check<N == sizeof(X<N>)> t; // expected-note {{in instantiation}}
15 };
16
17 check_alignment<1>::t c1;
18 check_alignment<2>::t c2;
19 check_alignment<3>::t c3; // expected-note 2 {{in instantiation}}
20 check_alignment<4>::t c4;
Douglas Gregord2472d42013-05-02 23:25:32 +000021
22 template<unsigned Size, unsigned Align>
23 class my_aligned_storage
24 {
Aaron Ballman87e7dea2014-01-13 21:30:03 +000025 __attribute__((aligned(Align))) char storage[Size];
Douglas Gregord2472d42013-05-02 23:25:32 +000026 };
27
28 template<typename T>
29 class C {
30 public:
31 C() {
32 static_assert(sizeof(t) == sizeof(T), "my_aligned_storage size wrong");
33 static_assert(alignof(t) == alignof(T), "my_aligned_storage align wrong"); // expected-warning{{'alignof' applied to an expression is a GNU extension}}
34 }
35
36 private:
37 my_aligned_storage<sizeof(T), alignof(T)> t;
38 };
39
40 C<double> cd;
Chandler Carruthf40c42f2010-06-25 03:22:07 +000041}
Douglas Gregorf892c7f2011-10-09 22:26:49 +000042
43namespace PR9049 {
44 extern const void *CFRetain(const void *ref);
45
46 template<typename T> __attribute__((cf_returns_retained))
47 inline T WBCFRetain(T aValue) { return aValue ? (T)CFRetain(aValue) : (T)0; }
48
49
50 extern void CFRelease(const void *ref);
51
52 template<typename T>
53 inline void WBCFRelease(__attribute__((cf_consumed)) T aValue) { if(aValue) CFRelease(aValue); }
54}