xref: /llvm-project/clang/test/Parser/cxx11-stmt-attributes.cpp (revision 60d3264d5fbe08fa93601ca40489d7c328941d0e)
1c202b280SRichard Smith // RUN: %clang_cc1 -fcxx-exceptions -fexceptions -fsyntax-only -verify -std=c++11 %s
2c202b280SRichard Smith 
foo(int i)3c202b280SRichard Smith void foo(int i) {
4c202b280SRichard Smith 
523214e50SMichael Han   [[unknown_attribute]] ; // expected-warning {{unknown attribute 'unknown_attribute' ignored}}
623214e50SMichael Han   [[unknown_attribute]] { } // expected-warning {{unknown attribute 'unknown_attribute' ignored}}
723214e50SMichael Han   [[unknown_attribute]] if (0) { } // expected-warning {{unknown attribute 'unknown_attribute' ignored}}
823214e50SMichael Han   [[unknown_attribute]] for (;;); // expected-warning {{unknown attribute 'unknown_attribute' ignored}}
923214e50SMichael Han   [[unknown_attribute]] do { // expected-warning {{unknown attribute 'unknown_attribute' ignored}}
1023214e50SMichael Han     [[unknown_attribute]] continue; // expected-warning {{unknown attribute 'unknown_attribute' ignored}}
11c202b280SRichard Smith   } while (0);
1223214e50SMichael Han   [[unknown_attribute]] while (0); // expected-warning {{unknown attribute 'unknown_attribute' ignored}}
13c202b280SRichard Smith 
1423214e50SMichael Han   [[unknown_attribute]] switch (i) { // expected-warning {{unknown attribute 'unknown_attribute' ignored}}
1523214e50SMichael Han     [[unknown_attribute]] case 0: // expected-warning {{unknown attribute 'unknown_attribute' ignored}}
1623214e50SMichael Han     [[unknown_attribute]] default: // expected-warning {{unknown attribute 'unknown_attribute' ignored}}
1723214e50SMichael Han       [[unknown_attribute]] break; // expected-warning {{unknown attribute 'unknown_attribute' ignored}}
18c202b280SRichard Smith   }
19c202b280SRichard Smith 
2023214e50SMichael Han   [[unknown_attribute]] goto here; // expected-warning {{unknown attribute 'unknown_attribute' ignored}}
2123214e50SMichael Han   [[unknown_attribute]] here: // expected-warning {{unknown attribute 'unknown_attribute' ignored}}
22c202b280SRichard Smith 
2323214e50SMichael Han   [[unknown_attribute]] try { // expected-warning {{unknown attribute 'unknown_attribute' ignored}}
24c202b280SRichard Smith   } catch (...) {
25c202b280SRichard Smith   }
26c202b280SRichard Smith 
2723214e50SMichael Han   [[unknown_attribute]] return; // expected-warning {{unknown attribute 'unknown_attribute' ignored}}
28c202b280SRichard Smith 
29c202b280SRichard Smith 
304c96e992SRichard Smith   alignas(8) ; // expected-error {{'alignas' attribute cannot be applied to a statement}}
314c96e992SRichard Smith   [[noreturn]] { } // expected-error {{'noreturn' attribute cannot be applied to a statement}}
324c96e992SRichard Smith   [[noreturn]] if (0) { } // expected-error {{'noreturn' attribute cannot be applied to a statement}}
334c96e992SRichard Smith   [[noreturn]] for (;;); // expected-error {{'noreturn' attribute cannot be applied to a statement}}
344c96e992SRichard Smith   [[noreturn]] do { // expected-error {{'noreturn' attribute cannot be applied to a statement}}
3523214e50SMichael Han     [[unavailable]] continue; // expected-warning {{unknown attribute 'unavailable' ignored}}
36c202b280SRichard Smith   } while (0);
3723214e50SMichael Han   [[unknown_attributqqq]] while (0); // expected-warning {{unknown attribute 'unknown_attributqqq' ignored}}
3823214e50SMichael Han 	// TODO: remove 'qqq' part and enjoy 'empty loop body' warning here (DiagnoseEmptyLoopBody)
39c202b280SRichard Smith 
4023214e50SMichael Han   [[unknown_attribute]] while (0); // expected-warning {{unknown attribute 'unknown_attribute' ignored}}
4123214e50SMichael Han 
4223214e50SMichael Han   [[unused]] switch (i) { // expected-warning {{unknown attribute 'unused' ignored}}
4323214e50SMichael Han     [[uuid]] case 0: // expected-warning {{unknown attribute 'uuid' ignored}}
4423214e50SMichael Han     [[visibility]] default: // expected-warning {{unknown attribute 'visibility' ignored}}
454c96e992SRichard Smith       [[carries_dependency]] break; // expected-error {{'carries_dependency' attribute cannot be applied to a statement}}
46c202b280SRichard Smith   }
47c202b280SRichard Smith 
4823214e50SMichael Han   [[fastcall]] goto there; // expected-warning {{unknown attribute 'fastcall' ignored}}
4923214e50SMichael Han   [[noinline]] there: // expected-warning {{unknown attribute 'noinline' ignored}}
50c202b280SRichard Smith 
5123214e50SMichael Han   [[lock_returned]] try { // expected-warning {{unknown attribute 'lock_returned' ignored}}
52c202b280SRichard Smith   } catch (...) {
53c202b280SRichard Smith   }
54c202b280SRichard Smith 
5523214e50SMichael Han   [[weakref]] return; // expected-warning {{unknown attribute 'weakref' ignored}}
5623214e50SMichael Han 
574c96e992SRichard Smith   [[carries_dependency]] ; // expected-error {{'carries_dependency' attribute cannot be applied to a statement}}
584c96e992SRichard Smith   [[carries_dependency]] { } // expected-error {{'carries_dependency' attribute cannot be applied to a statement}}
594c96e992SRichard Smith   [[carries_dependency]] if (0) { } // expected-error {{'carries_dependency' attribute cannot be applied to a statement}}
604c96e992SRichard Smith   [[carries_dependency]] for (;;); // expected-error {{'carries_dependency' attribute cannot be applied to a statement}}
614c96e992SRichard Smith   [[carries_dependency]] do { // expected-error {{'carries_dependency' attribute cannot be applied to a statement}}
624c96e992SRichard Smith     [[carries_dependency]] continue; // expected-error {{'carries_dependency' attribute cannot be applied to a statement}} ignored}}
6323214e50SMichael Han   } while (0);
644c96e992SRichard Smith   [[carries_dependency]] while (0); // expected-error {{'carries_dependency' attribute cannot be applied to a statement}}
6523214e50SMichael Han 
664c96e992SRichard Smith   [[carries_dependency]] switch (i) { // expected-error {{'carries_dependency' attribute cannot be applied to a statement}} ignored}}
674c96e992SRichard Smith     [[carries_dependency]] case 0: // expected-error {{'carries_dependency' attribute cannot be applied to a statement}}
684c96e992SRichard Smith     [[carries_dependency]] default: // expected-error {{'carries_dependency' attribute cannot be applied to a statement}}
694c96e992SRichard Smith       [[carries_dependency]] break; // expected-error {{'carries_dependency' attribute cannot be applied to a statement}}
7023214e50SMichael Han   }
7123214e50SMichael Han 
724c96e992SRichard Smith   [[carries_dependency]] goto here; // expected-error {{'carries_dependency' attribute cannot be applied to a statement}}
7323214e50SMichael Han 
744c96e992SRichard Smith   [[carries_dependency]] try { // expected-error {{'carries_dependency' attribute cannot be applied to a statement}}
7523214e50SMichael Han   } catch (...) {
7623214e50SMichael Han   }
7723214e50SMichael Han 
784c96e992SRichard Smith   [[carries_dependency]] return; // expected-error {{'carries_dependency' attribute cannot be applied to a statement}}
79ca9b0b68SRichard Smith 
80ca9b0b68SRichard Smith   {
81ca9b0b68SRichard Smith     [[ ]] // expected-error {{an attribute list cannot appear here}}
82ca9b0b68SRichard Smith #pragma STDC FP_CONTRACT ON // expected-error {{can only appear at file scope or at the start of a compound statement}}
83*60d3264dSAdam Nemet #pragma clang fp contract(fast) // expected-error {{can only appear at file scope or at the start of a compound statement}}
84ca9b0b68SRichard Smith   }
85c202b280SRichard Smith }
86