blob: de688b39bb60c146ca3f70cc990963fed7ddd058 [file] [log] [blame]
Rémy Oudompheng2ece2f52012-02-18 22:15:42 +01001// run
Russ Cox285b6022009-09-24 13:38:18 -07002
3// Copyright 2009 The Go Authors. All rights reserved.
4// Use of this source code is governed by a BSD-style
5// license that can be found in the LICENSE file.
6
Rob Pikefc0dc042012-02-19 13:19:43 +11007// Test that returning &T{} from a function causes an allocation.
8
Russ Cox285b6022009-09-24 13:38:18 -07009package main
10
11type T struct {
Rob Pike4f61fc92010-09-04 10:36:13 +100012 int
Russ Cox285b6022009-09-24 13:38:18 -070013}
14
15func f() *T {
16 return &T{1}
17}
18
19func main() {
Rob Pike4f61fc92010-09-04 10:36:13 +100020 x := f()
21 y := f()
Russ Cox285b6022009-09-24 13:38:18 -070022 if x == y {
Rob Pike4f61fc92010-09-04 10:36:13 +100023 panic("not allocating & composite literals")
Russ Cox285b6022009-09-24 13:38:18 -070024 }
25}