252
|
1 // RUN: %clang_cc1 -fsyntax-only -verify=expected,notc2x -Wno-strict-prototypes %s
|
236
|
2 // RUN: %clang_cc1 -fsyntax-only -std=gnu2x -verify=expected,c2x %s
|
150
|
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}}
|
236
|
37 [[]] int; // expected-error {{an attribute list cannot appear here}} \
|
|
38 // expected-warning {{declaration does not declare anything}}
|
150
|
39 };
|
|
40
|
|
41 [[]] struct S2 { int a; }; // expected-error {{misplaced attributes}}
|
|
42 struct S3 [[]] { int a; }; // expected-error {{an attribute list cannot appear here}}
|
|
43
|
|
44 union [[]] U {
|
|
45 double d [[]];
|
|
46 [[]] int i;
|
|
47 };
|
|
48
|
|
49 [[]] union U2 { double d; }; // expected-error {{misplaced attributes}}
|
|
50 union U3 [[]] { double d; }; // expected-error {{an attribute list cannot appear here}}
|
|
51
|
|
52 struct [[]] IncompleteStruct;
|
|
53 union [[]] IncompleteUnion;
|
|
54 enum [[]] IncompleteEnum;
|
|
55 enum __attribute__((deprecated)) IncompleteEnum2;
|
|
56
|
|
57 [[]] void f1(void);
|
|
58 void [[]] f2(void);
|
|
59 void f3 [[]] (void);
|
|
60 void f4(void) [[]];
|
|
61
|
|
62 void f5(int i [[]], [[]] int j, int [[]] k);
|
|
63
|
236
|
64 void f6(a, b) [[]] int a; int b; { // notc2x-error {{an attribute list cannot appear here}} \
|
|
65 c2x-error {{unknown type name 'a'}} \
|
|
66 c2x-error {{unknown type name 'b'}} \
|
|
67 c2x-error {{expected ';' after top level declarator}} \
|
|
68 c2x-error {{expected identifier or '('}}
|
150
|
69 }
|
|
70
|
|
71 // FIXME: technically, an attribute list cannot appear here, but we currently
|
|
72 // parse it as part of the return type of the function, which is reasonable
|
|
73 // behavior given that we *don't* want to parse it as part of the K&R parameter
|
|
74 // declarations. It is disallowed to avoid a parsing ambiguity we already
|
|
75 // handle well.
|
236
|
76 int (*f7(a, b))(int, int) [[]] int a; int b; { // c2x-error {{unknown type name 'a'}} \
|
|
77 c2x-error {{unknown type name 'b'}} \
|
|
78 c2x-error {{expected ';' after top level declarator}} \
|
|
79 c2x-error {{expected identifier or '('}}
|
|
80
|
150
|
81 return 0;
|
|
82 }
|
|
83
|
|
84 [[]] int a, b;
|
|
85 int c [[]], d [[]];
|
|
86
|
|
87 void f8(void) [[]] {
|
|
88 [[]] int i, j;
|
|
89 int k, l [[]];
|
|
90 }
|
|
91
|
|
92 [[]] void f9(void) {
|
|
93 int i[10] [[]];
|
|
94 int (*fp1)(void)[[]];
|
|
95 int (*fp2 [[]])(void);
|
|
96
|
|
97 int * [[]] *ipp;
|
|
98 }
|
|
99
|
|
100 void f10(int j[static 10] [[]], int k[*] [[]]);
|
|
101
|
|
102 void f11(void) {
|
|
103 [[]] {}
|
|
104 [[]] if (1) {}
|
|
105
|
|
106 [[]] switch (1) {
|
|
107 [[]] case 1: [[]] break;
|
|
108 [[]] default: break;
|
|
109 }
|
|
110
|
|
111 goto foo;
|
|
112 [[]] foo: (void)1;
|
|
113
|
|
114 [[]] for (;;);
|
|
115 [[]] while (1);
|
|
116 [[]] do [[]] { } while(1);
|
|
117
|
|
118 [[]] (void)1;
|
|
119
|
|
120 [[]];
|
|
121
|
|
122 (void)sizeof(int [4][[]]);
|
|
123 (void)sizeof(struct [[]] S3 { int a [[]]; });
|
|
124
|
|
125 [[]] return;
|
|
126 }
|
|
127
|
|
128 [[attr]] void f12(void); // expected-warning {{unknown attribute 'attr' ignored}}
|
|
129 [[vendor::attr]] void f13(void); // expected-warning {{unknown attribute 'attr' ignored}}
|
|
130
|
|
131 // Ensure that asm statements properly handle double colons.
|
|
132 void test_asm(void) {
|
|
133 asm("ret" :::);
|
|
134 asm("foo" :: "r" (xx)); // expected-error {{use of undeclared identifier 'xx'}}
|
|
135 }
|
|
136
|
|
137 // Do not allow 'using' to introduce vendor attribute namespaces.
|
221
|
138 [[using vendor: attr1, attr2]] void f14(void); // expected-error {{expected ','}} \
|
150
|
139 // expected-warning {{unknown attribute 'using' ignored}}
|
|
140
|
|
141 struct [[]] S4 *s; // expected-error {{an attribute list cannot appear here}}
|
|
142 struct S5 {};
|
|
143 int c = sizeof(struct [[]] S5); // expected-error {{an attribute list cannot appear here}}
|
236
|
144
|
|
145 // Ensure that '::' outside of attributes does not crash and is not treated as scope
|
|
146 double n::v; // expected-error {{expected ';' after top level declarator}}
|