aboutsummaryrefslogtreecommitdiff
path: root/test/escape.go
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2010-03-26 18:01:02 -0700
committerRuss Cox <rsc@golang.org>2010-03-26 18:01:02 -0700
commit97d0e8fe6ce41b5961e776ad08abdf0cb6d7af85 (patch)
treed4d8dc0972b2f8222ae7bf5d427f91dac28a16e8 /test/escape.go
parent5a716206a4b680ef6e24e5bc424d19f5d35a7162 (diff)
downloadgo-97d0e8fe6ce41b5961e776ad08abdf0cb6d7af85.tar.gz
go-97d0e8fe6ce41b5961e776ad08abdf0cb6d7af85.zip
gc: allow taking address of out parameters
Fixes #186. R=ken2 CC=golang-dev https://golang.org/cl/793041
Diffstat (limited to 'test/escape.go')
-rw-r--r--test/escape.go32
1 files changed, 32 insertions, 0 deletions
diff --git a/test/escape.go b/test/escape.go
index 2c5881d49c..19c08a5276 100644
--- a/test/escape.go
+++ b/test/escape.go
@@ -141,6 +141,24 @@ func for_escapes2(x int, y int) (*int, *int) {
return p[0], p[1]
}
+func out_escapes(i int) (x int, p *int) {
+ x = i
+ p = &x; // ERROR "address of out parameter"
+ return;
+}
+
+func out_escapes_2(i int) (x int, p *int) {
+ x = i
+ return x, &x; // ERROR "address of out parameter"
+}
+
+func defer1(i int) (x int) {
+ c := make(chan int)
+ go func() { x = i; c <- 1 }()
+ <-c
+ return
+}
+
func main() {
p, q := i_escapes(1), i_escapes(2);
chk(p, q, 1, "i_escapes");
@@ -169,6 +187,20 @@ func main() {
p, q = for_escapes2(103, 104);
chkalias(p, q, 103, "for_escapes2");
+ _, p = out_escapes(15)
+ _, q = out_escapes(16);
+ chk(p, q, 15, "out_escapes");
+
+ _, p = out_escapes_2(17)
+ _, q = out_escapes_2(18);
+ chk(p, q, 17, "out_escapes_2");
+
+ x := defer1(20)
+ if x != 20 {
+ println("defer failed", x)
+ bad = true
+ }
+
if bad {
panic("BUG: no escape");
}