Black Lives Matter. Support the Equal Justice Initiative.

Text file src/go/types/testdata/check/importC.src

Documentation: go/types/testdata/check

     1  // Copyright 2015 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package importC
     6  
     7  import "C"
     8  import _ /* ERROR cannot rename import "C" */ "C"
     9  import foo /* ERROR cannot rename import "C" */ "C"
    10  import . /* ERROR cannot rename import "C" */ "C"
    11  
    12  // Test cases extracted from issue #22090.
    13  
    14  import "unsafe"
    15  
    16  const _ C.int = 0xff // no error due to invalid constant type
    17  
    18  type T struct {
    19  	Name    string
    20  	Ordinal int
    21  }
    22  
    23  func _(args []T) {
    24  	var s string
    25  	for i, v := range args {
    26  		cname := C.CString(v.Name)
    27  		args[i].Ordinal = int(C.sqlite3_bind_parameter_index(s, cname)) // no error due to i not being "used"
    28  		C.free(unsafe.Pointer(cname))
    29  	}
    30  }
    31  
    32  type CType C.Type
    33  
    34  const _ CType = C.X // no error due to invalid constant type
    35  const _ = C.X
    36  
    37  // Test cases extracted from issue #23712.
    38  
    39  func _() {
    40  	var a [C.ArrayLength]byte
    41  	_ = a[0] // no index out of bounds error here
    42  }
    43  
    44  // Additional tests to verify fix for #23712.
    45  
    46  func _() {
    47  	var a [C.ArrayLength1]byte
    48  	_ = 1 / len(a) // no division by zero error here and below
    49  	_ = 1 / cap(a)
    50  	_ = uint(unsafe.Sizeof(a)) // must not be negative
    51  
    52  	var b [C.ArrayLength2]byte
    53  	a = b // should be valid
    54  }
    55  

View as plain text