2012-02-18 14:15:42 -07:00
|
|
|
// run
|
2009-09-24 14:38:18 -06:00
|
|
|
|
|
|
|
// Copyright 2009 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2012-02-18 19:19:43 -07:00
|
|
|
// Test that returning &T{} from a function causes an allocation.
|
|
|
|
|
2009-09-24 14:38:18 -06:00
|
|
|
package main
|
|
|
|
|
|
|
|
type T struct {
|
2010-09-03 18:36:13 -06:00
|
|
|
int
|
2009-09-24 14:38:18 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func f() *T {
|
|
|
|
return &T{1}
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
2010-09-03 18:36:13 -06:00
|
|
|
x := f()
|
|
|
|
y := f()
|
2009-09-24 14:38:18 -06:00
|
|
|
if x == y {
|
2010-09-03 18:36:13 -06:00
|
|
|
panic("not allocating & composite literals")
|
2009-09-24 14:38:18 -06:00
|
|
|
}
|
|
|
|
}
|