blob: 22d61a1978fb2ab2dac86495ef774984ebc5ab98 [file] [log] [blame]
Alp Tokerbb17ff92013-10-28 23:47:09 +00001// RUN: %clang_cc1 -triple x86_64-unknown-unknown -std=c++11 -verify %s
Richard Smithd6e7fae2013-01-14 08:57:42 +00002
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;
Richard Smithd03de6a2013-01-29 10:02:16 +00008// expected-error@-1 {{'unused' attribute cannot be applied to types}}
Richard Smithd6e7fae2013-01-14 08:57:42 +00009int *[[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
Rafael Espindola7e66ed32013-10-21 18:24:30 +000014void aliasb [[gnu::alias("_Z6alias1v")]] ();
Richard Smithd6e7fae2013-01-14 08:57:42 +000015void alias1() {}
Rafael Espindola7e66ed32013-10-21 18:24:30 +000016void aliasa [[gnu::alias("_Z6alias1v")]] ();
Richard Smithd6e7fae2013-01-14 08:57:42 +000017
18[[gnu::aligned(8)]] int aligned;
19void aligned_fn [[gnu::aligned(32)]] ();
20struct [[gnu::aligned(8)]] aligned_struct {};
21
22[[gnu::malloc, gnu::alloc_size(1,2)]] void *alloc_size(int a, int b);
23
24void always_inline [[gnu::always_inline]] ();
25
26__thread int tls_model [[gnu::tls_model("local-exec")]];
27
28void cleanup(int *p) {
29 int n [[gnu::cleanup(cleanup)]];
30}
31
32void deprecated1 [[gnu::deprecated]] (); // expected-note {{here}}
33[[gnu::deprecated("custom message")]] void deprecated2(); // expected-note {{here}}
34void deprecated3() {
35 deprecated1(); // expected-warning {{deprecated}}
36 deprecated2(); // expected-warning {{custom message}}
37}
38
39[[gnu::naked(1,2,3)]] void naked(); // expected-error {{takes no arguments}}
40
41void nonnull [[gnu::nonnull]] (); // expected-warning {{applied to function with no pointer arguments}}
42
Richard Smith5c521662013-01-15 02:48:13 +000043// [[gnu::noreturn]] appertains to a declaration, and marks the innermost
44// function declarator in that declaration as being noreturn.
Richard Smithd6e7fae2013-01-14 08:57:42 +000045int noreturn [[gnu::noreturn]]; // expected-warning {{'noreturn' only applies to function types}}
Richard Smith5c521662013-01-15 02:48:13 +000046int noreturn_fn_1();
47int noreturn_fn_2() [[gnu::noreturn]]; // expected-warning {{cannot be applied to a type}}
48int noreturn_fn_3 [[gnu::noreturn]] ();
49[[gnu::noreturn]] int noreturn_fn_4();
50int (*noreturn_fn_ptr_1 [[gnu::noreturn]])() = &noreturn_fn_1; // expected-error {{cannot initialize}}
51int (*noreturn_fn_ptr_2 [[gnu::noreturn]])() = &noreturn_fn_3;
52[[gnu::noreturn]] int (*noreturn_fn_ptr_3)() = &noreturn_fn_1; // expected-error {{cannot initialize}}
53[[gnu::noreturn]] int (*noreturn_fn_ptr_4)() = &noreturn_fn_3;
Richard Smithd6e7fae2013-01-14 08:57:42 +000054
55struct [[gnu::packed]] packed { char c; int n; };
56static_assert(sizeof(packed) == sizeof(char) + sizeof(int), "not packed");