blob: f261dee200a766f75f075143461e963191697cf8 [file] [log] [blame]
Aaron Ballman606093a2017-10-15 15:01:42 +00001// RUN: %clang_cc1 -fsyntax-only -fdouble-square-bracket-attributes -verify %s
2
3enum [[]] E {
4 One [[]],
5 Two,
6 Three [[]]
7};
8
9enum [[]] { Four };
Faisal Valic5089c02017-12-25 22:23:20 +000010[[]] enum E2 { Five }; // expected-error {{misplaced attributes}}
Aaron Ballman606093a2017-10-15 15:01:42 +000011
12// FIXME: this diagnostic can be improved.
13enum { [[]] Six }; // expected-error {{expected identifier}}
14
15// FIXME: this diagnostic can be improved.
16enum E3 [[]] { Seven }; // expected-error {{expected identifier or '('}}
17
18struct [[]] 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 Valic5089c02017-12-25 22:23:20 +000027[[]] struct S2 { int a; }; // expected-error {{misplaced attributes}}
Aaron Ballman606093a2017-10-15 15:01:42 +000028struct S3 [[]] { int a; }; // expected-error {{an attribute list cannot appear here}}
29
30union [[]] U {
31 double d [[]];
32 [[]] int i;
33};
34
Faisal Valic5089c02017-12-25 22:23:20 +000035[[]] union U2 { double d; }; // expected-error {{misplaced attributes}}
Aaron Ballman606093a2017-10-15 15:01:42 +000036union U3 [[]] { double d; }; // expected-error {{an attribute list cannot appear here}}
37
38struct [[]] IncompleteStruct;
39union [[]] IncompleteUnion;
40enum [[]] IncompleteEnum;
41enum __attribute__((deprecated)) IncompleteEnum2;
42
43[[]] void f1(void);
44void [[]] f2(void);
45void f3 [[]] (void);
46void f4(void) [[]];
47
48void f5(int i [[]], [[]] int j, int [[]] k);
49
50void 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.
58int (*f7(a, b))(int, int) [[]] int a; int b; {
59 return 0;
60}
61
62[[]] int a, b;
63int c [[]], d [[]];
64
65void 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
78void f10(int j[static 10] [[]], int k[*] [[]]);
79
80void 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.
110void 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
120struct [[]] S4 *s; // expected-error {{an attribute list cannot appear here}}
121struct S5 {};
122int c = sizeof(struct [[]] S5); // expected-error {{an attribute list cannot appear here}}