| Aaron Ballman | 606093a | 2017-10-15 15:01:42 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -fdouble-square-bracket-attributes -verify %s |
| 2 | |
| 3 | enum [[]] E { |
| 4 | One [[]], |
| 5 | Two, |
| 6 | Three [[]] |
| 7 | }; |
| 8 | |
| 9 | enum [[]] { Four }; |
| Faisal Vali | c5089c0 | 2017-12-25 22:23:20 +0000 | [diff] [blame] | 10 | [[]] enum E2 { Five }; // expected-error {{misplaced attributes}} |
| Aaron Ballman | 606093a | 2017-10-15 15:01:42 +0000 | [diff] [blame] | 11 | |
| 12 | // FIXME: this diagnostic can be improved. |
| 13 | enum { [[]] Six }; // expected-error {{expected identifier}} |
| 14 | |
| 15 | // FIXME: this diagnostic can be improved. |
| 16 | enum E3 [[]] { Seven }; // expected-error {{expected identifier or '('}} |
| 17 | |
| 18 | struct [[]] S1 { |
| 19 | int i [[]]; |
| 20 | int [[]] j; |
| 21 | int k[10] [[]]; |
| 22 | int l[[]][10]; |
| 23 | [[]] int m, n; |
| 24 | int o [[]] : 12; |
| 25 | }; |
| 26 | |
| Faisal Vali | c5089c0 | 2017-12-25 22:23:20 +0000 | [diff] [blame] | 27 | [[]] struct S2 { int a; }; // expected-error {{misplaced attributes}} |
| Aaron Ballman | 606093a | 2017-10-15 15:01:42 +0000 | [diff] [blame] | 28 | struct S3 [[]] { int a; }; // expected-error {{an attribute list cannot appear here}} |
| 29 | |
| 30 | union [[]] U { |
| 31 | double d [[]]; |
| 32 | [[]] int i; |
| 33 | }; |
| 34 | |
| Faisal Vali | c5089c0 | 2017-12-25 22:23:20 +0000 | [diff] [blame] | 35 | [[]] union U2 { double d; }; // expected-error {{misplaced attributes}} |
| Aaron Ballman | 606093a | 2017-10-15 15:01:42 +0000 | [diff] [blame] | 36 | union U3 [[]] { double d; }; // expected-error {{an attribute list cannot appear here}} |
| 37 | |
| 38 | struct [[]] IncompleteStruct; |
| 39 | union [[]] IncompleteUnion; |
| 40 | enum [[]] IncompleteEnum; |
| 41 | enum __attribute__((deprecated)) IncompleteEnum2; |
| 42 | |
| 43 | [[]] void f1(void); |
| 44 | void [[]] f2(void); |
| 45 | void f3 [[]] (void); |
| 46 | void f4(void) [[]]; |
| 47 | |
| 48 | void f5(int i [[]], [[]] int j, int [[]] k); |
| 49 | |
| 50 | void f6(a, b) [[]] int a; int b; { // expected-error {{an attribute list cannot appear here}} |
| 51 | } |
| 52 | |
| 53 | // FIXME: technically, an attribute list cannot appear here, but we currently |
| 54 | // parse it as part of the return type of the function, which is reasonable |
| 55 | // behavior given that we *don't* want to parse it as part of the K&R parameter |
| 56 | // declarations. It is disallowed to avoid a parsing ambiguity we already |
| 57 | // handle well. |
| 58 | int (*f7(a, b))(int, int) [[]] int a; int b; { |
| 59 | return 0; |
| 60 | } |
| 61 | |
| 62 | [[]] int a, b; |
| 63 | int c [[]], d [[]]; |
| 64 | |
| 65 | void f8(void) [[]] { |
| 66 | [[]] int i, j; |
| 67 | int k, l [[]]; |
| 68 | } |
| 69 | |
| 70 | [[]] void f9(void) { |
| 71 | int i[10] [[]]; |
| 72 | int (*fp1)(void)[[]]; |
| 73 | int (*fp2 [[]])(void); |
| 74 | |
| 75 | int * [[]] *ipp; |
| 76 | } |
| 77 | |
| 78 | void f10(int j[static 10] [[]], int k[*] [[]]); |
| 79 | |
| 80 | void f11(void) { |
| 81 | [[]] {} |
| 82 | [[]] if (1) {} |
| 83 | |
| 84 | [[]] switch (1) { |
| 85 | [[]] case 1: [[]] break; |
| 86 | [[]] default: break; |
| 87 | } |
| 88 | |
| 89 | goto foo; |
| 90 | [[]] foo: (void)1; |
| 91 | |
| 92 | [[]] for (;;); |
| 93 | [[]] while (1); |
| 94 | [[]] do [[]] { } while(1); |
| 95 | |
| 96 | [[]] (void)1; |
| 97 | |
| 98 | [[]]; |
| 99 | |
| 100 | (void)sizeof(int [4][[]]); |
| 101 | (void)sizeof(struct [[]] S3 { int a [[]]; }); |
| 102 | |
| 103 | [[]] return; |
| 104 | } |
| 105 | |
| 106 | [[attr]] void f12(void); // expected-warning {{unknown attribute 'attr' ignored}} |
| 107 | [[vendor::attr]] void f13(void); // expected-warning {{unknown attribute 'attr' ignored}} |
| 108 | |
| 109 | // Ensure that asm statements properly handle double colons. |
| 110 | void test_asm(void) { |
| 111 | asm("ret" :::); |
| 112 | asm("foo" :: "r" (xx)); // expected-error {{use of undeclared identifier 'xx'}} |
| 113 | } |
| 114 | |
| 115 | // Do not allow 'using' to introduce vendor attribute namespaces. |
| 116 | [[using vendor: attr1, attr2]] void f14(void); // expected-error {{expected ']'}} \ |
| 117 | // expected-warning {{unknown attribute 'vendor' ignored}} \ |
| 118 | // expected-warning {{unknown attribute 'using' ignored}} |
| 119 | |
| 120 | struct [[]] S4 *s; // expected-error {{an attribute list cannot appear here}} |
| 121 | struct S5 {}; |
| 122 | int c = sizeof(struct [[]] S5); // expected-error {{an attribute list cannot appear here}} |