aboutsummaryrefslogtreecommitdiff
path: root/tests/conformance/4-statements/defer_block.zc
blob: 44246885c26d937212325a305743a99ae8eafbbc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// expect: 1 2 30 31 9 /1 2 4 30 31 /5 3 /
// spec 4.14.1: the block form `defer { ... }`, with no semicolon after it: several statements and a local of its own, run at every exit of the scope
include rt;
void pn(int x) { rt.put_n(x); rt.put_c(32); }
int f(int c) {
	defer {
		int k = 30;
		pn(k);
		pn(k + 1);
	}
	pn(1);
	pn(2);
	if (c) { pn(4); return 0; }
	return 9;
}
fn main() {
	pn(f(0)); rt.put_c(10);
	f(1); rt.put_c(10);
	{ defer { pn(3); } pn(5); }
	rt.put_c(10);
	return 0;
}
// zc0: skip