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