From: Robert Griesemer
Date: Wed, 24 Mar 2010 00:30:14 +0000 (-0700)
Subject: go spec: modification of defer statement
X-Git-Tag: weekly.2010-03-30~79
X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=48f0cd2bd55357b41fa2d6ac3bf82d2a0042d3dd;p=gostls13.git
go spec: modification of defer statement
R=r, rsc, ken2, iant
CC=golang-dev
https://golang.org/cl/708041
---
diff --git a/doc/go_spec.html b/doc/go_spec.html
index 2262d7d99e..89fbcb73ae 100644
--- a/doc/go_spec.html
+++ b/doc/go_spec.html
@@ -2996,8 +2996,6 @@ which must be addressable,
that is, either a variable, pointer indirection, array or slice indexing
operation,
or a field selector of an addressable struct operand.
-A function result variable is not addressable.
-
Given an operand of pointer type, the pointer indirection
operator *
retrieves the value pointed
to by the operand.
@@ -4281,7 +4279,12 @@ executes, the parameters to the function call are evaluated and saved anew but t
function is not invoked.
Deferred function calls are executed in LIFO order
immediately before the surrounding function returns,
-but after the return values, if any, have been evaluated.
+after the return values, if any, have been evaluated, but before they
+are returned to the caller. For instance, if the deferred function is
+a function literal and the surrounding
+function has named result parameters that
+are in scope within the literal, the deferred function may access and modify
+the result parameters before they are returned.
@@ -4292,6 +4295,14 @@ defer unlock(l) // unlocking happens before surrounding function returns
for i := 0; i <= 3; i++ {
defer fmt.Print(i)
}
+
+// f returns 1
+func f() (result int) {
+ defer func() {
+ result++
+ }()
+ return 0
+}
Built-in functions
@@ -4928,7 +4939,8 @@ The following minimal alignment properties are guaranteed:
Implementation differences - TODO
- Implementation does not honor the restriction on goto statements and targets (no intervening declarations).
- - Method expressions are not implemented.
- - The implementation of complex numbers is incomplete.
+ - Method expressions are partially implemented.
- Gccgo allows only one init() function per source file.
+ - Deferred functions cannot access the surrounding function's result parameters.
+ - Function results are not addressable.