From 2833024aa47da6f9d0d1bbf30265e63aa03d435d Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Fri, 26 Mar 2010 18:01:02 -0700 Subject: gc: allow taking address of out parameters Fixes issue 186. R=ken2 CC=golang-dev http://codereview.appspot.com/793041 --- test/escape.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'test/escape.go') diff --git a/test/escape.go b/test/escape.go index 2c5881d49..19c08a527 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"); } -- cgit v1.2.1