...

Source file src/cmd/cgo/internal/testshared/testdata/exe/exe.go

Documentation: cmd/cgo/internal/testshared/testdata/exe

     1  package main
     2  
     3  import (
     4  	"os"
     5  	"reflect"
     6  	"runtime"
     7  
     8  	"testshared/depBase"
     9  )
    10  
    11  // Having a function declared in the main package triggered
    12  // golang.org/issue/18250
    13  func DeclaredInMain() {
    14  }
    15  
    16  type C struct {
    17  }
    18  
    19  func F() *C {
    20  	return nil
    21  }
    22  
    23  var slicePtr interface{} = &[]int{}
    24  
    25  func main() {
    26  	defer depBase.ImplementedInAsm()
    27  	// This code below causes various go.itab.* symbols to be generated in
    28  	// the executable. Similar code in ../depBase/dep.go results in
    29  	// exercising https://golang.org/issues/17594
    30  	reflect.TypeOf(os.Stdout).Elem()
    31  	runtime.GC()
    32  	depBase.V = depBase.F() + 1
    33  
    34  	var c *C
    35  	if reflect.TypeOf(F).Out(0) != reflect.TypeOf(c) {
    36  		panic("bad reflection results, see golang.org/issue/18252")
    37  	}
    38  
    39  	sp := reflect.New(reflect.TypeOf(slicePtr).Elem())
    40  	s := sp.Interface()
    41  
    42  	if reflect.TypeOf(s) != reflect.TypeOf(slicePtr) {
    43  		panic("bad reflection results, see golang.org/issue/18729")
    44  	}
    45  }
    46  

View as plain text