aboutsummaryrefslogtreecommitdiff
path: root/tests/conformance
diff options
context:
space:
mode:
Diffstat (limited to 'tests/conformance')
-rw-r--r--tests/conformance/4-statements/defer_block.zc23
1 files changed, 23 insertions, 0 deletions
diff --git a/tests/conformance/4-statements/defer_block.zc b/tests/conformance/4-statements/defer_block.zc
new file mode 100644
index 0000000..4424688
--- /dev/null
+++ b/tests/conformance/4-statements/defer_block.zc
@@ -0,0 +1,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