xref: /llvm-project/clang/test/SemaCXX/cxx11-gnu-attrs.cpp (revision 18c7689698dbad06020ad3ebdfa57602326443dc)
1 // RUN: %clang -cc1 -triple x86_64-unknown-unknown -std=c++11 -verify %s
2 
3 // Error cases.
4 
5 [[gnu::this_attribute_does_not_exist]] int unknown_attr;
6 // expected-warning@-1 {{unknown attribute 'this_attribute_does_not_exist' ignored}}
7 int [[gnu::unused]] attr_on_type;
8 // expected-warning@-1 {{attribute 'unused' ignored, because it is not attached to a declaration}}
9 int *[[gnu::unused]] attr_on_ptr;
10 // expected-warning@-1 {{attribute 'unused' ignored, because it cannot be applied to a type}}
11 
12 // Valid cases.
13 
14 void alias1() {}
15 void alias2 [[gnu::alias("_Z6alias1v")]] ();
16 
17 [[gnu::aligned(8)]] int aligned;
18 void aligned_fn [[gnu::aligned(32)]] ();
19 struct [[gnu::aligned(8)]] aligned_struct {};
20 
21 [[gnu::malloc, gnu::alloc_size(1,2)]] void *alloc_size(int a, int b);
22 
23 void always_inline [[gnu::always_inline]] ();
24 
25 __thread int tls_model [[gnu::tls_model("local-exec")]];
26 
27 void cleanup(int *p) {
28   int n [[gnu::cleanup(cleanup)]];
29 }
30 
31 void deprecated1 [[gnu::deprecated]] (); // expected-note {{here}}
32 [[gnu::deprecated("custom message")]] void deprecated2(); // expected-note {{here}}
33 void deprecated3() {
34   deprecated1(); // expected-warning {{deprecated}}
35   deprecated2(); // expected-warning {{custom message}}
36 }
37 
38 [[gnu::naked(1,2,3)]] void naked(); // expected-error {{takes no arguments}}
39 
40 void nonnull [[gnu::nonnull]] (); // expected-warning {{applied to function with no pointer arguments}}
41 
42 int noreturn [[gnu::noreturn]]; // expected-warning {{'noreturn' only applies to function types}}
43 
44 struct [[gnu::packed]] packed { char c; int n; };
45 static_assert(sizeof(packed) == sizeof(char) + sizeof(int), "not packed");
46