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