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}}
7int [[gnu::unused]] attr_on_type;
8// expected-error@-1 {{'unused' attribute cannot be applied to types}}
9int *[[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
14void aliasb [[gnu::alias("_Z6alias1v")]] ();
15void alias1() {}
16void aliasa [[gnu::alias("_Z6alias1v")]] ();
17
18[[gnu::aligned(8)]] int aligned;
19void aligned_fn [[gnu::aligned(32)]] ();
20struct [[gnu::aligned(8)]] aligned_struct {};
21
22void always_inline [[gnu::always_inline]] ();
23
24__thread int tls_model [[gnu::tls_model("local-exec")]];
25
26void cleanup(int *p) {
27  int n [[gnu::cleanup(cleanup)]];
28}
29
30void deprecated1 [[gnu::deprecated]] (); // expected-note {{here}}
31[[gnu::deprecated("custom message")]] void deprecated2(); // expected-note {{here}}
32void deprecated3() {
33  deprecated1(); // expected-warning {{deprecated}}
34  deprecated2(); // expected-warning {{custom message}}
35}
36
37[[gnu::naked(1,2,3)]] void naked(); // expected-error {{takes no arguments}}
38
39void nonnull [[gnu::nonnull]] (); // expected-warning {{applied to function with no pointer arguments}}
40
41// [[gnu::noreturn]] appertains to a declaration, and marks the innermost
42// function declarator in that declaration as being noreturn.
43int noreturn [[gnu::noreturn]]; // expected-warning {{'noreturn' only applies to function types}}
44int noreturn_fn_1();
45int noreturn_fn_2() [[gnu::noreturn]]; // expected-warning {{cannot be applied to a type}}
46int noreturn_fn_3 [[gnu::noreturn]] ();
47[[gnu::noreturn]] int noreturn_fn_4();
48int (*noreturn_fn_ptr_1 [[gnu::noreturn]])() = &noreturn_fn_1; // expected-error {{cannot initialize}}
49int (*noreturn_fn_ptr_2 [[gnu::noreturn]])() = &noreturn_fn_3;
50[[gnu::noreturn]] int (*noreturn_fn_ptr_3)() = &noreturn_fn_1; // expected-error {{cannot initialize}}
51[[gnu::noreturn]] int (*noreturn_fn_ptr_4)() = &noreturn_fn_3;
52
53struct [[gnu::packed]] packed { char c; int n; };
54static_assert(sizeof(packed) == sizeof(char) + sizeof(int), "not packed");
55