diff options
author | Russ Cox <rsc@golang.org> | 2010-03-26 18:01:02 -0700 |
---|---|---|
committer | Russ Cox <rsc@golang.org> | 2010-03-26 18:01:02 -0700 |
commit | 2833024aa47da6f9d0d1bbf30265e63aa03d435d (patch) | |
tree | e5a03e10cafa59f726579395f85e30de69e0d1e1 /test/escape.go | |
parent | 42a860370795c49686910978b9486479c2c95f40 (diff) | |
download | go-2833024aa47da6f9d0d1bbf30265e63aa03d435d.tar.gz |
gc: allow taking address of out parameters
Fixes issue 186.
R=ken2
CC=golang-dev
http://codereview.appspot.com/793041
Diffstat (limited to 'test/escape.go')
-rw-r--r-- | test/escape.go | 32 |
1 files changed, 32 insertions, 0 deletions
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"); } |