From a3450d687628661aa0316cfc995934f6ce0c4e90 Mon Sep 17 00:00:00 2001 From: zinc Date: Wed, 14 Oct 2026 19:56:53 +0330 Subject: defer: any single statement (if/else, loops, switch, unchecked, unbounded), not just an expression or a block --- docs/SPEC.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs/SPEC.md') diff --git a/docs/SPEC.md b/docs/SPEC.md index 32afdfb..aad7ff6 100644 --- a/docs/SPEC.md +++ b/docs/SPEC.md @@ -640,7 +640,7 @@ int y = 7; asm { y @ 1 + y ! } // y is 8 ### 4.14 defer -4.14.1 `defer expr;` and `defer { statements }` register a statement that runs when the block that contains the `defer` ends. the tokens are kept, not compiled, at the `defer`; the compiler compiles them again, in place, at every point where control leaves the block: the end of the block, and a `return`, `break` or `continue` that leaves it. (a function body is a block; so are a loop or `if` body, a `switch` case and a block expression.) the code is therefore duplicated at each exit. +4.14.1 `defer` followed by one statement (`defer expr;`, `defer { statements }`, `defer if (c) a; else b;`, a loop, a `switch`, or an `unchecked` or `unbounded` statement) registers that statement; it runs when the block that contains the `defer` ends. the tokens are kept, not compiled, at the `defer`; the compiler compiles them again, in place, at every point where control leaves the block: the end of the block, and a `return`, `break` or `continue` that leaves it. (a function body is a block; so are a loop or `if` body, a `switch` case and a block expression.) the code is therefore duplicated at each exit. 4.14.2 several defers in one block run in reverse order of registration. an early exit runs the defers of every block it leaves, innermost block first, and within a block newest first. `return` runs those of the whole function, `break` and `continue` only those inside the loop or switch they leave. -- cgit v1.2.3