Alp Toker | bb17ff9 | 2013-10-28 23:47:09 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -triple x86_64-unknown-unknown -std=c++11 -verify %s |
Richard Smith | d6e7fae | 2013-01-14 08:57:42 +0000 | [diff] [blame] | 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; |
Richard Smith | d03de6a | 2013-01-29 10:02:16 +0000 | [diff] [blame] | 8 | // expected-error@-1 {{'unused' attribute cannot be applied to types}} |
Richard Smith | d6e7fae | 2013-01-14 08:57:42 +0000 | [diff] [blame] | 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 | |
Rafael Espindola | 7e66ed3 | 2013-10-21 18:24:30 +0000 | [diff] [blame] | 14 | void aliasb [[gnu::alias("_Z6alias1v")]] (); |
Richard Smith | d6e7fae | 2013-01-14 08:57:42 +0000 | [diff] [blame] | 15 | void alias1() {} |
Rafael Espindola | 7e66ed3 | 2013-10-21 18:24:30 +0000 | [diff] [blame] | 16 | void aliasa [[gnu::alias("_Z6alias1v")]] (); |
Richard Smith | d6e7fae | 2013-01-14 08:57:42 +0000 | [diff] [blame] | 17 | |
Stephen Hines | 0e2c34f | 2015-03-23 12:09:02 -0700 | [diff] [blame] | 18 | extern struct PR22493Ty { |
| 19 | } PR22493 [[gnu::alias("_ZN7pcrecpp2RE6no_argE")]]; |
| 20 | |
Richard Smith | d6e7fae | 2013-01-14 08:57:42 +0000 | [diff] [blame] | 21 | [[gnu::aligned(8)]] int aligned; |
| 22 | void aligned_fn [[gnu::aligned(32)]] (); |
| 23 | struct [[gnu::aligned(8)]] aligned_struct {}; |
| 24 | |
Richard Smith | d6e7fae | 2013-01-14 08:57:42 +0000 | [diff] [blame] | 25 | void always_inline [[gnu::always_inline]] (); |
| 26 | |
| 27 | __thread int tls_model [[gnu::tls_model("local-exec")]]; |
| 28 | |
| 29 | void cleanup(int *p) { |
| 30 | int n [[gnu::cleanup(cleanup)]]; |
| 31 | } |
| 32 | |
| 33 | void deprecated1 [[gnu::deprecated]] (); // expected-note {{here}} |
| 34 | [[gnu::deprecated("custom message")]] void deprecated2(); // expected-note {{here}} |
| 35 | void deprecated3() { |
| 36 | deprecated1(); // expected-warning {{deprecated}} |
| 37 | deprecated2(); // expected-warning {{custom message}} |
| 38 | } |
| 39 | |
| 40 | [[gnu::naked(1,2,3)]] void naked(); // expected-error {{takes no arguments}} |
| 41 | |
| 42 | void nonnull [[gnu::nonnull]] (); // expected-warning {{applied to function with no pointer arguments}} |
| 43 | |
Richard Smith | 5c52166 | 2013-01-15 02:48:13 +0000 | [diff] [blame] | 44 | // [[gnu::noreturn]] appertains to a declaration, and marks the innermost |
| 45 | // function declarator in that declaration as being noreturn. |
Richard Smith | d6e7fae | 2013-01-14 08:57:42 +0000 | [diff] [blame] | 46 | int noreturn [[gnu::noreturn]]; // expected-warning {{'noreturn' only applies to function types}} |
Richard Smith | 5c52166 | 2013-01-15 02:48:13 +0000 | [diff] [blame] | 47 | int noreturn_fn_1(); |
| 48 | int noreturn_fn_2() [[gnu::noreturn]]; // expected-warning {{cannot be applied to a type}} |
| 49 | int noreturn_fn_3 [[gnu::noreturn]] (); |
| 50 | [[gnu::noreturn]] int noreturn_fn_4(); |
| 51 | int (*noreturn_fn_ptr_1 [[gnu::noreturn]])() = &noreturn_fn_1; // expected-error {{cannot initialize}} |
| 52 | int (*noreturn_fn_ptr_2 [[gnu::noreturn]])() = &noreturn_fn_3; |
| 53 | [[gnu::noreturn]] int (*noreturn_fn_ptr_3)() = &noreturn_fn_1; // expected-error {{cannot initialize}} |
| 54 | [[gnu::noreturn]] int (*noreturn_fn_ptr_4)() = &noreturn_fn_3; |
Richard Smith | d6e7fae | 2013-01-14 08:57:42 +0000 | [diff] [blame] | 55 | |
| 56 | struct [[gnu::packed]] packed { char c; int n; }; |
| 57 | static_assert(sizeof(packed) == sizeof(char) + sizeof(int), "not packed"); |