aboutsummaryrefslogtreecommitdiff
path: root/misc/cgo/errors/testdata/err2.go
blob: a90598fe35b6304434bba7253c29b1d62173dcc4 (plain)
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// Copyright 2013 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 main

/*
#include <stdio.h>

typedef struct foo foo_t;
typedef struct bar bar_t;

foo_t *foop;

long double x = 0;

static int transform(int x) { return x; }

typedef void v;
void F(v** p) {}

void fvi(void *p, int x) {}

void fppi(int** p) {}

int i;
void fi(int i) {}
*/
import "C"
import (
	"unsafe"
)

func main() {
	s := ""
	_ = s
	C.malloc(s) // ERROR HERE

	x := (*C.bar_t)(nil)
	C.foop = x // ERROR HERE

	// issue 13129: used to output error about C.unsignedshort with CC=clang
	var x1 C.ushort
	x1 = int(0) // ERROR HERE: C\.ushort

	// issue 13423
	_ = C.fopen() // ERROR HERE

	// issue 13467
	var x2 rune = '✈'
	var _ rune = C.transform(x2) // ERROR HERE: C\.int

	// issue 13635: used to output error about C.unsignedchar.
	// This test tests all such types.
	var (
		_ C.uchar         = "uc"  // ERROR HERE: C\.uchar
		_ C.schar         = "sc"  // ERROR HERE: C\.schar
		_ C.ushort        = "us"  // ERROR HERE: C\.ushort
		_ C.uint          = "ui"  // ERROR HERE: C\.uint
		_ C.ulong         = "ul"  // ERROR HERE: C\.ulong
		_ C.longlong      = "ll"  // ERROR HERE: C\.longlong
		_ C.ulonglong     = "ull" // ERROR HERE: C\.ulonglong
		_ C.complexfloat  = "cf"  // ERROR HERE: C\.complexfloat
		_ C.complexdouble = "cd"  // ERROR HERE: C\.complexdouble
	)

	// issue 13830
	// cgo converts C void* to Go unsafe.Pointer, so despite appearances C
	// void** is Go *unsafe.Pointer. This test verifies that we detect the
	// problem at build time.
	{
		type v [0]byte

		f := func(p **v) {
			C.F((**C.v)(unsafe.Pointer(p))) // ERROR HERE
		}
		var p *v
		f(&p)
	}

	// issue 16116
	_ = C.fvi(1) // ERROR HERE

	// Issue 16591: Test that we detect an invalid call that was being
	// hidden by a type conversion inserted by cgo checking.
	{
		type x *C.int
		var p *x
		C.fppi(p) // ERROR HERE
	}

	// issue 26745
	_ = func(i int) int {
		return C.i + 1 // ERROR HERE: 14
	}
	_ = func(i int) {
		C.fi(i) // ERROR HERE: 7
	}

	C.fi = C.fi // ERROR HERE

}