annotate clang/test/Parser/c2x-attributes.c @ 150:1d019706d866

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