github.com/mdempsky/go@v0.0.0-20151201204031-5dd372bd1e70/test/live2.go (about)

     1  // errorcheck -0 -live -wb=0
     2  
     3  // Copyright 2014 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  
     7  // liveness tests with inlining ENABLED
     8  // see also live.go.
     9  
    10  package main
    11  
    12  // issue 8142: lost 'addrtaken' bit on inlined variables.
    13  // no inlining in this test, so just checking that non-inlined works.
    14  
    15  func printnl()
    16  
    17  type T40 struct {
    18  	m map[int]int
    19  }
    20  
    21  func newT40() *T40 {
    22  	ret := T40{}
    23  	ret.m = make(map[int]int) // ERROR "live at call to makemap: &ret"
    24  	return &ret
    25  }
    26  
    27  func bad40() {
    28  	t := newT40() // ERROR "live at call to makemap: autotmp_.* ret"
    29  	printnl()     // ERROR "live at call to printnl: autotmp_.* ret"
    30  	_ = t
    31  }
    32  
    33  func good40() {
    34  	ret := T40{}
    35  	ret.m = make(map[int]int) // ERROR "live at call to makemap: autotmp_.* ret"
    36  	t := &ret
    37  	printnl() // ERROR "live at call to printnl: autotmp_.* ret"
    38  	_ = t
    39  }