xref: /aosp_15_r20/external/clang/test/Parser/cxx11-stmt-attributes.cpp (revision 67e74705e28f6214e480b399dd47ea732279e315)
1*67e74705SXin Li // RUN: %clang_cc1 -fcxx-exceptions -fexceptions -fsyntax-only -verify -std=c++11 %s
2*67e74705SXin Li 
foo(int i)3*67e74705SXin Li void foo(int i) {
4*67e74705SXin Li 
5*67e74705SXin Li   [[unknown_attribute]] ; // expected-warning {{unknown attribute 'unknown_attribute' ignored}}
6*67e74705SXin Li   [[unknown_attribute]] { } // expected-warning {{unknown attribute 'unknown_attribute' ignored}}
7*67e74705SXin Li   [[unknown_attribute]] if (0) { } // expected-warning {{unknown attribute 'unknown_attribute' ignored}}
8*67e74705SXin Li   [[unknown_attribute]] for (;;); // expected-warning {{unknown attribute 'unknown_attribute' ignored}}
9*67e74705SXin Li   [[unknown_attribute]] do { // expected-warning {{unknown attribute 'unknown_attribute' ignored}}
10*67e74705SXin Li     [[unknown_attribute]] continue; // expected-warning {{unknown attribute 'unknown_attribute' ignored}}
11*67e74705SXin Li   } while (0);
12*67e74705SXin Li   [[unknown_attribute]] while (0); // expected-warning {{unknown attribute 'unknown_attribute' ignored}}
13*67e74705SXin Li 
14*67e74705SXin Li   [[unknown_attribute]] switch (i) { // expected-warning {{unknown attribute 'unknown_attribute' ignored}}
15*67e74705SXin Li     [[unknown_attribute]] case 0: // expected-warning {{unknown attribute 'unknown_attribute' ignored}}
16*67e74705SXin Li     [[unknown_attribute]] default: // expected-warning {{unknown attribute 'unknown_attribute' ignored}}
17*67e74705SXin Li       [[unknown_attribute]] break; // expected-warning {{unknown attribute 'unknown_attribute' ignored}}
18*67e74705SXin Li   }
19*67e74705SXin Li 
20*67e74705SXin Li   [[unknown_attribute]] goto here; // expected-warning {{unknown attribute 'unknown_attribute' ignored}}
21*67e74705SXin Li   [[unknown_attribute]] here: // expected-warning {{unknown attribute 'unknown_attribute' ignored}}
22*67e74705SXin Li 
23*67e74705SXin Li   [[unknown_attribute]] try { // expected-warning {{unknown attribute 'unknown_attribute' ignored}}
24*67e74705SXin Li   } catch (...) {
25*67e74705SXin Li   }
26*67e74705SXin Li 
27*67e74705SXin Li   [[unknown_attribute]] return; // expected-warning {{unknown attribute 'unknown_attribute' ignored}}
28*67e74705SXin Li 
29*67e74705SXin Li 
30*67e74705SXin Li   alignas(8) ; // expected-error {{'alignas' attribute cannot be applied to a statement}}
31*67e74705SXin Li   [[noreturn]] { } // expected-error {{'noreturn' attribute cannot be applied to a statement}}
32*67e74705SXin Li   [[noreturn]] if (0) { } // expected-error {{'noreturn' attribute cannot be applied to a statement}}
33*67e74705SXin Li   [[noreturn]] for (;;); // expected-error {{'noreturn' attribute cannot be applied to a statement}}
34*67e74705SXin Li   [[noreturn]] do { // expected-error {{'noreturn' attribute cannot be applied to a statement}}
35*67e74705SXin Li     [[unavailable]] continue; // expected-warning {{unknown attribute 'unavailable' ignored}}
36*67e74705SXin Li   } while (0);
37*67e74705SXin Li   [[unknown_attributqqq]] while (0); // expected-warning {{unknown attribute 'unknown_attributqqq' ignored}}
38*67e74705SXin Li 	// TODO: remove 'qqq' part and enjoy 'empty loop body' warning here (DiagnoseEmptyLoopBody)
39*67e74705SXin Li 
40*67e74705SXin Li   [[unknown_attribute]] while (0); // expected-warning {{unknown attribute 'unknown_attribute' ignored}}
41*67e74705SXin Li 
42*67e74705SXin Li   [[unused]] switch (i) { // expected-warning {{unknown attribute 'unused' ignored}}
43*67e74705SXin Li     [[uuid]] case 0: // expected-warning {{unknown attribute 'uuid' ignored}}
44*67e74705SXin Li     [[visibility]] default: // expected-warning {{unknown attribute 'visibility' ignored}}
45*67e74705SXin Li       [[carries_dependency]] break; // expected-error {{'carries_dependency' attribute cannot be applied to a statement}}
46*67e74705SXin Li   }
47*67e74705SXin Li 
48*67e74705SXin Li   [[fastcall]] goto there; // expected-warning {{unknown attribute 'fastcall' ignored}}
49*67e74705SXin Li   [[noinline]] there: // expected-warning {{unknown attribute 'noinline' ignored}}
50*67e74705SXin Li 
51*67e74705SXin Li   [[lock_returned]] try { // expected-warning {{unknown attribute 'lock_returned' ignored}}
52*67e74705SXin Li   } catch (...) {
53*67e74705SXin Li   }
54*67e74705SXin Li 
55*67e74705SXin Li   [[weakref]] return; // expected-warning {{unknown attribute 'weakref' ignored}}
56*67e74705SXin Li 
57*67e74705SXin Li   [[carries_dependency]] ; // expected-error {{'carries_dependency' attribute cannot be applied to a statement}}
58*67e74705SXin Li   [[carries_dependency]] { } // expected-error {{'carries_dependency' attribute cannot be applied to a statement}}
59*67e74705SXin Li   [[carries_dependency]] if (0) { } // expected-error {{'carries_dependency' attribute cannot be applied to a statement}}
60*67e74705SXin Li   [[carries_dependency]] for (;;); // expected-error {{'carries_dependency' attribute cannot be applied to a statement}}
61*67e74705SXin Li   [[carries_dependency]] do { // expected-error {{'carries_dependency' attribute cannot be applied to a statement}}
62*67e74705SXin Li     [[carries_dependency]] continue; // expected-error {{'carries_dependency' attribute cannot be applied to a statement}} ignored}}
63*67e74705SXin Li   } while (0);
64*67e74705SXin Li   [[carries_dependency]] while (0); // expected-error {{'carries_dependency' attribute cannot be applied to a statement}}
65*67e74705SXin Li 
66*67e74705SXin Li   [[carries_dependency]] switch (i) { // expected-error {{'carries_dependency' attribute cannot be applied to a statement}} ignored}}
67*67e74705SXin Li     [[carries_dependency]] case 0: // expected-error {{'carries_dependency' attribute cannot be applied to a statement}}
68*67e74705SXin Li     [[carries_dependency]] default: // expected-error {{'carries_dependency' attribute cannot be applied to a statement}}
69*67e74705SXin Li       [[carries_dependency]] break; // expected-error {{'carries_dependency' attribute cannot be applied to a statement}}
70*67e74705SXin Li   }
71*67e74705SXin Li 
72*67e74705SXin Li   [[carries_dependency]] goto here; // expected-error {{'carries_dependency' attribute cannot be applied to a statement}}
73*67e74705SXin Li 
74*67e74705SXin Li   [[carries_dependency]] try { // expected-error {{'carries_dependency' attribute cannot be applied to a statement}}
75*67e74705SXin Li   } catch (...) {
76*67e74705SXin Li   }
77*67e74705SXin Li 
78*67e74705SXin Li   [[carries_dependency]] return; // expected-error {{'carries_dependency' attribute cannot be applied to a statement}}
79*67e74705SXin Li 
80*67e74705SXin Li   {
81*67e74705SXin Li     [[ ]] // expected-error {{an attribute list cannot appear here}}
82*67e74705SXin Li #pragma STDC FP_CONTRACT ON // expected-error {{can only appear at file scope or at the start of a compound statement}}
83*67e74705SXin Li   }
84*67e74705SXin Li }
85