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