xref: /aosp_15_r20/external/clang/test/SemaCXX/cxx11-gnu-attrs.cpp (revision 67e74705e28f6214e480b399dd47ea732279e315)
1*67e74705SXin Li // RUN: %clang_cc1 -triple x86_64-unknown-unknown -std=c++11 -verify %s
2*67e74705SXin Li 
3*67e74705SXin Li // Error cases.
4*67e74705SXin Li 
5*67e74705SXin Li [[gnu::this_attribute_does_not_exist]] int unknown_attr;
6*67e74705SXin Li // expected-warning@-1 {{unknown attribute 'this_attribute_does_not_exist' ignored}}
7*67e74705SXin Li int [[gnu::unused]] attr_on_type;
8*67e74705SXin Li // expected-error@-1 {{'unused' attribute cannot be applied to types}}
9*67e74705SXin Li int *[[gnu::unused]] attr_on_ptr;
10*67e74705SXin Li // expected-warning@-1 {{attribute 'unused' ignored, because it cannot be applied to a type}}
11*67e74705SXin Li [[gnu::fastcall]] void pr17424_1();
12*67e74705SXin Li // expected-warning@-1 {{calling convention 'fastcall' ignored for this target}}
13*67e74705SXin Li [[gnu::fastcall]] [[gnu::stdcall]] void pr17424_2();
14*67e74705SXin Li // expected-warning@-1 {{calling convention 'fastcall' ignored for this target}}
15*67e74705SXin Li // expected-warning@-2 {{calling convention 'stdcall' ignored for this target}}
16*67e74705SXin Li [[gnu::fastcall]] __stdcall void pr17424_3();
17*67e74705SXin Li // expected-warning@-1 {{calling convention 'fastcall' ignored for this target}}
18*67e74705SXin Li // expected-warning@-2 {{calling convention '__stdcall' ignored for this target}}
19*67e74705SXin Li [[gnu::fastcall]] void pr17424_4() [[gnu::stdcall]];
20*67e74705SXin Li // expected-warning@-1 {{calling convention 'fastcall' ignored for this target}}
21*67e74705SXin Li // expected-warning@-2 {{attribute 'stdcall' ignored, because it cannot be applied to a type}}
22*67e74705SXin Li // expected-warning@-3 {{calling convention 'stdcall' ignored for this target}}
23*67e74705SXin Li void pr17424_5 [[gnu::fastcall]]();
24*67e74705SXin Li // expected-warning@-1 {{calling convention 'fastcall' ignored for this target}}
25*67e74705SXin Li 
26*67e74705SXin Li // Valid cases.
27*67e74705SXin Li 
28*67e74705SXin Li void aliasb [[gnu::alias("_Z6alias1v")]] ();
alias1()29*67e74705SXin Li void alias1() {}
30*67e74705SXin Li void aliasa [[gnu::alias("_Z6alias1v")]] ();
31*67e74705SXin Li 
32*67e74705SXin Li extern struct PR22493Ty {
33*67e74705SXin Li } PR22493 [[gnu::alias("_ZN7pcrecpp2RE6no_argE")]];
34*67e74705SXin Li 
35*67e74705SXin Li [[gnu::aligned(8)]] int aligned;
36*67e74705SXin Li void aligned_fn [[gnu::aligned(32)]] ();
37*67e74705SXin Li struct [[gnu::aligned(8)]] aligned_struct {};
38*67e74705SXin Li 
39*67e74705SXin Li void always_inline [[gnu::always_inline]] ();
40*67e74705SXin Li 
41*67e74705SXin Li __thread int tls_model [[gnu::tls_model("local-exec")]];
42*67e74705SXin Li 
cleanup(int * p)43*67e74705SXin Li void cleanup(int *p) {
44*67e74705SXin Li   int n [[gnu::cleanup(cleanup)]];
45*67e74705SXin Li }
46*67e74705SXin Li 
47*67e74705SXin Li void deprecated1 [[gnu::deprecated]] (); // expected-note {{here}}
48*67e74705SXin Li [[gnu::deprecated("custom message")]] void deprecated2(); // expected-note {{here}}
deprecated3()49*67e74705SXin Li void deprecated3() {
50*67e74705SXin Li   deprecated1(); // expected-warning {{deprecated}}
51*67e74705SXin Li   deprecated2(); // expected-warning {{custom message}}
52*67e74705SXin Li }
53*67e74705SXin Li 
54*67e74705SXin Li [[gnu::naked(1,2,3)]] void naked(); // expected-error {{takes no arguments}}
55*67e74705SXin Li 
56*67e74705SXin Li void nonnull [[gnu::nonnull]] (); // expected-warning {{applied to function with no pointer arguments}}
57*67e74705SXin Li 
58*67e74705SXin Li // [[gnu::noreturn]] appertains to a declaration, and marks the innermost
59*67e74705SXin Li // function declarator in that declaration as being noreturn.
60*67e74705SXin Li int noreturn [[gnu::noreturn]]; // expected-warning {{'noreturn' only applies to function types}}
61*67e74705SXin Li int noreturn_fn_1();
62*67e74705SXin Li int noreturn_fn_2() [[gnu::noreturn]]; // expected-warning {{cannot be applied to a type}}
63*67e74705SXin Li int noreturn_fn_3 [[gnu::noreturn]] ();
64*67e74705SXin Li [[gnu::noreturn]] int noreturn_fn_4();
65*67e74705SXin Li int (*noreturn_fn_ptr_1 [[gnu::noreturn]])() = &noreturn_fn_1; // expected-error {{cannot initialize}}
66*67e74705SXin Li int (*noreturn_fn_ptr_2 [[gnu::noreturn]])() = &noreturn_fn_3;
67*67e74705SXin Li [[gnu::noreturn]] int (*noreturn_fn_ptr_3)() = &noreturn_fn_1; // expected-error {{cannot initialize}}
68*67e74705SXin Li [[gnu::noreturn]] int (*noreturn_fn_ptr_4)() = &noreturn_fn_3;
69*67e74705SXin Li 
70*67e74705SXin Li struct [[gnu::packed]] packed { char c; int n; };
71*67e74705SXin Li static_assert(sizeof(packed) == sizeof(char) + sizeof(int), "not packed");
72