Douglas Gregor | d2472d4 | 2013-05-02 23:25:32 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -std=gnu++11 -fsyntax-only -verify %s |
Richard Smith | 33bddbd | 2018-01-04 23:42:29 +0000 | [diff] [blame^] | 2 | // RUN: not %clang_cc1 -std=gnu++11 -ast-dump %s | FileCheck %s |
Douglas Gregor | bdb604a | 2010-05-18 23:01:22 +0000 | [diff] [blame] | 3 | |
Chandler Carruth | f40c42f | 2010-06-25 03:22:07 +0000 | [diff] [blame] | 4 | namespace 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 Gregor | bdb604a | 2010-05-18 23:01:22 +0000 | [diff] [blame] | 9 | |
Chandler Carruth | f40c42f | 2010-06-25 03:22:07 +0000 | [diff] [blame] | 10 | template <bool X> struct check { |
Chandler Carruth | a92409c | 2011-01-04 04:44:35 +0000 | [diff] [blame] | 11 | int check_failed[X ? 1 : -1]; // expected-error {{array with a negative size}} |
Chandler Carruth | f40c42f | 2010-06-25 03:22:07 +0000 | [diff] [blame] | 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; |
Douglas Gregor | d2472d4 | 2013-05-02 23:25:32 +0000 | [diff] [blame] | 22 | |
| 23 | template<unsigned Size, unsigned Align> |
| 24 | class my_aligned_storage |
| 25 | { |
Aaron Ballman | 87e7dea | 2014-01-13 21:30:03 +0000 | [diff] [blame] | 26 | __attribute__((aligned(Align))) char storage[Size]; |
Douglas Gregor | d2472d4 | 2013-05-02 23:25:32 +0000 | [diff] [blame] | 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; |
Chandler Carruth | f40c42f | 2010-06-25 03:22:07 +0000 | [diff] [blame] | 42 | } |
Douglas Gregor | f892c7f | 2011-10-09 22:26:49 +0000 | [diff] [blame] | 43 | |
| 44 | namespace 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 Smith | 33bddbd | 2018-01-04 23:42:29 +0000 | [diff] [blame^] | 56 | |
| 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" |
| 64 | template<typename T> [[clang::annotate("ANNOTATE_FOO"), clang::annotate("ANNOTATE_BAR")]] void HasAnnotations(); |
| 65 | void UseAnnotations() { HasAnnotations<int>(); } |