Rémy Oudompheng | 2ece2f5 | 2012-02-18 22:15:42 +0100 | [diff] [blame] | 1 | // run |
Russ Cox | 285b602 | 2009-09-24 13:38:18 -0700 | [diff] [blame] | 2 | |
| 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 Pike | fc0dc04 | 2012-02-19 13:19:43 +1100 | [diff] [blame] | 7 | // Test that returning &T{} from a function causes an allocation. |
| 8 | |
Russ Cox | 285b602 | 2009-09-24 13:38:18 -0700 | [diff] [blame] | 9 | package main |
| 10 | |
| 11 | type T struct { |
Rob Pike | 4f61fc9 | 2010-09-04 10:36:13 +1000 | [diff] [blame] | 12 | int |
Russ Cox | 285b602 | 2009-09-24 13:38:18 -0700 | [diff] [blame] | 13 | } |
| 14 | |
| 15 | func f() *T { |
| 16 | return &T{1} |
| 17 | } |
| 18 | |
| 19 | func main() { |
Rob Pike | 4f61fc9 | 2010-09-04 10:36:13 +1000 | [diff] [blame] | 20 | x := f() |
| 21 | y := f() |
Russ Cox | 285b602 | 2009-09-24 13:38:18 -0700 | [diff] [blame] | 22 | if x == y { |
Rob Pike | 4f61fc9 | 2010-09-04 10:36:13 +1000 | [diff] [blame] | 23 | panic("not allocating & composite literals") |
Russ Cox | 285b602 | 2009-09-24 13:38:18 -0700 | [diff] [blame] | 24 | } |
| 25 | } |