[lld][WebAssembly] Reinstate mistakenly disabled test. NFC
[llvm-project.git] / clang / test / Parser / c2x-attributes.c
blobd75e9e2d29768b7790ea96fffbd678755485d7eb
1 // RUN: %clang_cc1 -fsyntax-only -fdouble-square-bracket-attributes -verify %s
2 // RUN: %clang_cc1 -fsyntax-only -std=gnu2x -verify %s
4 enum [[]] E {
5 One [[]],
6 Two,
7 Three [[]]
8 };
10 enum [[]] { Four };
11 [[]] enum E2 { Five }; // expected-error {{misplaced attributes}}
13 // FIXME: this diagnostic can be improved.
14 enum { [[]] Six }; // expected-error {{expected identifier}}
16 // FIXME: this diagnostic can be improved.
17 enum E3 [[]] { Seven }; // expected-error {{expected identifier or '('}}
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}}
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;
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}}
39 [[]] struct S2 { int a; }; // expected-error {{misplaced attributes}}
40 struct S3 [[]] { int a; }; // expected-error {{an attribute list cannot appear here}}
42 union [[]] U {
43 double d [[]];
44 [[]] int i;
47 [[]] union U2 { double d; }; // expected-error {{misplaced attributes}}
48 union U3 [[]] { double d; }; // expected-error {{an attribute list cannot appear here}}
50 struct [[]] IncompleteStruct;
51 union [[]] IncompleteUnion;
52 enum [[]] IncompleteEnum;
53 enum __attribute__((deprecated)) IncompleteEnum2;
55 [[]] void f1(void);
56 void [[]] f2(void);
57 void f3 [[]] (void);
58 void f4(void) [[]];
60 void f5(int i [[]], [[]] int j, int [[]] k);
62 void f6(a, b) [[]] int a; int b; { // expected-error {{an attribute list cannot appear here}}
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;
74 [[]] int a, b;
75 int c [[]], d [[]];
77 void f8(void) [[]] {
78 [[]] int i, j;
79 int k, l [[]];
82 [[]] void f9(void) {
83 int i[10] [[]];
84 int (*fp1)(void)[[]];
85 int (*fp2 [[]])(void);
87 int * [[]] *ipp;
90 void f10(int j[static 10] [[]], int k[*] [[]]);
92 void f11(void) {
93 [[]] {}
94 [[]] if (1) {}
96 [[]] switch (1) {
97 [[]] case 1: [[]] break;
98 [[]] default: break;
101 goto foo;
102 [[]] foo: (void)1;
104 [[]] for (;;);
105 [[]] while (1);
106 [[]] do [[]] { } while(1);
108 [[]] (void)1;
110 [[]];
112 (void)sizeof(int [4][[]]);
113 (void)sizeof(struct [[]] S3 { int a [[]]; });
115 [[]] return;
118 [[attr]] void f12(void); // expected-warning {{unknown attribute 'attr' ignored}}
119 [[vendor::attr]] void f13(void); // expected-warning {{unknown attribute 'attr' ignored}}
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'}}
127 // Do not allow 'using' to introduce vendor attribute namespaces.
128 [[using vendor: attr1, attr2]] void f14(void); // expected-error {{expected ','}} \
129 // expected-warning {{unknown attribute 'using' ignored}}
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}}