-
Notifications
You must be signed in to change notification settings - Fork 11
/
testthings.w
269 lines (225 loc) · 5.12 KB
/
testthings.w
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
@s atomic int
@* Attributes. This is just all of the examples from the sections about
attributes in the \CEE/ and \CPLUSPLUS/ standards collected together, with most
comments removed.
@c
[[using CC: opt(1), debug]]
void f() {}
[[using CC: opt(1)]] [[CC::debug]]
void g() {}
[[using CC: CC::opt(1)]]
void h() {}
int p[10];
void f() {
int x = 42, y[5];
int i [[vendor::attr([[]])]];
}
alignas(double) unsigned char c[sizeof(double)];
extern unsigned char c[sizeof(double)];
struct foo { int* a; int* b; };
std::atomic<struct foo *> foo_head[10];
int foo_array[10][10];
[[carries_dependency]] struct foo* f(int i) {
return foo_head[i].load(memory_order::consume);
}
int g(int* x, int* y [[carries_dependency]]) {
return kill_dependency(foo_array[*x][*y]);
}
[[carries_dependency]] struct foo* f(int i);
int g(int* x, int* y [[carries_dependency]]);
int c = 3;
void h(int i) {
struct foo* p;
p = f(i);
do_something_with(g(&c, p->a));
do_something_with(g(p->a, &c));
}
void f(int n) {
void g(), h(), i();
switch (n) {
case 1:
case 2:
g();
[[fallthrough]];
case 3:
do {
[[fallthrough]];
} while (false);
case 6:
do {
[[fallthrough]];
} while (n--);
case 7:
while (false) {
[[fallthrough]];
}
case 5:
h();
case 4:
i();
[[fallthrough]];
}
}
void g(int);
int f(int n) {
if (n > 5) [[unlikely]] {
g(0);
return n * 2 + 1;
}
switch (n) {
case 1:
g(1);
[[fallthrough]];
[[likely]] case 2:
g(2);
break;
}
return 3;
}
[[maybe_unused]] void f([[maybe_unused]] bool thing1,
[[maybe_unused]] bool thing2) {
[[maybe_unused]] bool b = thing1 && thing2;
assert(b);
}
struct [[nodiscard]] my_scopeguard { int x; };
struct my_unique {
my_unique() = default;
[[nodiscard]] my_unique(int fd) { /* \dots */ }
~my_unique() noexcept { /* \dots */ }
/* \dots */
};
struct [[nodiscard]] error_info { /* \dots */ };
error_info enable_missile_safety_mode();
void launch_missiles();
void test_missiles() {
my_scopeguard();
(void)my_scopeguard(),
launch_missiles();
my_unique(42);
my_unique();
enable_missile_safety_mode();
launch_missiles();
}
error_info &foo();
void f() { foo(); }
[[ noreturn ]] void f() {
throw "error";
}
[[ noreturn ]] void q(int i) {
if (i > 0)
throw "positive";
}
template<typename Key, typename Value,
typename Hash, typename Pred, typename Allocator>
class hash_map {
[[no_unique_address]] Hash hasher;
[[no_unique_address]] Pred pred;
[[no_unique_address]] Allocator alloc;
Bucket *buckets;
public:
};
[[deprecated, hal::daisy]] double nine1000(double);
[[deprecated]] [[hal::daisy]] double nine1000(double);
[[deprecated]] double nine1000 [[hal::daisy]] (double);
[[__deprecated__, __hal__::__daisy__]] double nine1000(double);
[[__deprecated__]] [[__hal__::__daisy__]] double nine1000(double);
[[__deprecated__]] double nine1000 [[__hal__::__daisy__]] (double);
[[hal::daisy, hal::rosie]] double nine999(double);
[[hal::rosie, hal::daisy]] double nine999(double);
[[hal::daisy]] [[hal::rosie]] double nine999(double);
[[hal::rosie]] [[hal::daisy]] double nine999(double);
struct [[nodiscard]] error_info { /*\dots*/ };
struct error_info enable_missile_safety_mode(void);
void launch_missiles(void);
void test_missiles(void) {
enable_missile_safety_mode();
launch_missiles();
}
[[nodiscard]] int important_func(void);
void call(void) {
int i = important_func();
}
[[nodiscard("must check armed state")]]
bool arm_detonator(int);
void call(void) {
arm_detonator(3);
detonate();
}
[[maybe_unused]] void f([[maybe_unused]] int i) {
[[maybe_unused]] int j = i + 100;
assert(j);
}
struct [[deprecated]] S {
int a;
};
enum [[deprecated]] E1 {
one
};
enum E2 {
two [[deprecated("use ’three’ instead")]],
three
};
[[deprecated]] typedef int Foo;
void f1(struct S s) {
int i = one;
int j = two;
int k = three;
Foo f;
}
[[deprecated]] void f2(struct S s) {
int i = one;
int j = two;
int k = three;
Foo f;
}
struct [[deprecated]] T {
Foo f;
struct S s;
};
void f(int n) {
void g(void), h(void), i(void);
switch (n) {
case 1: /* diagnostic on fallthrough discouraged */
case 2:
g();
[[fallthrough]];
case 3: /* diagnostic on fallthrough discouraged */
h();
case 4: /* fallthrough diagnostic encouraged */
i();
[[fallthrough]]; /* constraint violation */
}
}
@* Numbers. Here are new numbers.
@c
int main(void)
{
int decimal_integer = 100;
int hex_integer = 0x42;
int octal_integer = 0240;
int binary_integer = 0b10101011;
int separated_integer = 100'000'000;
float binary_exponent = 0x1FFFFp10;
float separated_float = 123.456'789'000e2;
int normal_exponent = 123'456e789;
}
@* Lists and Enumerations.
@c
int func(int,int,double); /* Rule 14 */
typedef enum {
false, true /* Rule 4 */
} boolean;
typedef struct {
int w, h; /* Rule 33 */
} area;
typedef int int_t, *intp_t, (&fp)(int,ulong), arr_t[10];
/* Rule 118 (and Rule 117) */
int func(int a, int b, double c) /* Rule 14 */
{
int t,u,v; /* Rule 33 */
return a;
}
template<typename Key, typename Value,
typename Hash, typename Pred, typename Allocator> /* Rule 153 */
class hash_map { };
@* Index.