[clang] Handle __declspec() attributes in using
[llvm-project.git] / clang / test / Parser / c2x-attributes.c
blobe3201e2315d2f92d908d3a625aced280b6a75952
1 // RUN: %clang_cc1 -fsyntax-only -fdouble-square-bracket-attributes -verify=expected,notc2x -Wno-strict-prototypes %s
2 // RUN: %clang_cc1 -fsyntax-only -std=gnu2x -verify=expected,c2x %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}}
37 [[]] int; // expected-error {{an attribute list cannot appear here}} \
38 // expected-warning {{declaration does not declare anything}}
41 [[]] struct S2 { int a; }; // expected-error {{misplaced attributes}}
42 struct S3 [[]] { int a; }; // expected-error {{an attribute list cannot appear here}}
44 union [[]] U {
45 double d [[]];
46 [[]] int i;
49 [[]] union U2 { double d; }; // expected-error {{misplaced attributes}}
50 union U3 [[]] { double d; }; // expected-error {{an attribute list cannot appear here}}
52 struct [[]] IncompleteStruct;
53 union [[]] IncompleteUnion;
54 enum [[]] IncompleteEnum;
55 enum __attribute__((deprecated)) IncompleteEnum2;
57 [[]] void f1(void);
58 void [[]] f2(void);
59 void f3 [[]] (void);
60 void f4(void) [[]];
62 void f5(int i [[]], [[]] int j, int [[]] k);
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 '('}}
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.
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 '('}}
81 return 0;
84 [[]] int a, b;
85 int c [[]], d [[]];
87 void f8(void) [[]] {
88 [[]] int i, j;
89 int k, l [[]];
92 [[]] void f9(void) {
93 int i[10] [[]];
94 int (*fp1)(void)[[]];
95 int (*fp2 [[]])(void);
97 int * [[]] *ipp;
100 void f10(int j[static 10] [[]], int k[*] [[]]);
102 void f11(void) {
103 [[]] {}
104 [[]] if (1) {}
106 [[]] switch (1) {
107 [[]] case 1: [[]] break;
108 [[]] default: break;
111 goto foo;
112 [[]] foo: (void)1;
114 [[]] for (;;);
115 [[]] while (1);
116 [[]] do [[]] { } while(1);
118 [[]] (void)1;
120 [[]];
122 (void)sizeof(int [4][[]]);
123 (void)sizeof(struct [[]] S3 { int a [[]]; });
125 [[]] return;
128 [[attr]] void f12(void); // expected-warning {{unknown attribute 'attr' ignored}}
129 [[vendor::attr]] void f13(void); // expected-warning {{unknown attribute 'attr' ignored}}
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'}}
137 // Do not allow 'using' to introduce vendor attribute namespaces.
138 [[using vendor: attr1, attr2]] void f14(void); // expected-error {{expected ','}} \
139 // expected-warning {{unknown attribute 'using' ignored}}
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}}
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}}