Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/cgo: compiler error for C unsigned short is wrong. #13129

Closed
ghost opened this issue Nov 3, 2015 · 5 comments
Closed

cmd/cgo: compiler error for C unsigned short is wrong. #13129

ghost opened this issue Nov 3, 2015 · 5 comments

Comments

@ghost
Copy link

ghost commented Nov 3, 2015

When trying to assign a variable of the wrong type to a C.ushort. The compiler will emit the error cannot use <var> (type <var type>) as type C.unsignedshort in assignment. However C.unsignedshort isn't even a real type. It should say C.ushort

short test program:
package main

import "C"

func main() {
    var x C.ushort
    y := 5
    x = y // ./bug.go:8: cannot use y (type int) as type C.unsignedshort in assignment
    //var z C.unsignedshort // could not determine kind of name for C.unsignedshor
}
@ghost ghost changed the title compiler error for C unsigned short is wrong. cgo: compiler error for C unsigned short is wrong. Nov 3, 2015
@ianlancetaylor ianlancetaylor changed the title cgo: compiler error for C unsigned short is wrong. cmd/cgo: compiler error for C unsigned short is wrong. Nov 3, 2015
@ianlancetaylor ianlancetaylor added this to the Unplanned milestone Nov 3, 2015
@mdempsky
Copy link
Member

@hydroflame Are you still able to reproduce this? If so, can you provide additional details about your build environment (at least Go version and OS).

I can't reproduce this issue at master (e36bf61) on linux/amd64 (Ubuntu 14.04):

$ go build bug.go
# command-line-arguments
./bug.go:8: cannot use y (type int) as type C.ushort in assignment

$ cat bug.go
package main

import "C"

func main() {
    var x C.ushort
    y := 5
    x = y // ./bug.go:8: cannot use y (type int) as type C.unsignedshort in assignment
    //var z C.unsignedshort // could not determine kind of name for C.unsignedshor
}

@mdempsky
Copy link
Member

Ah, nevermind, I can repro with Clang:

$ CC=clang-3.5 go build bug.go
# command-line-arguments
./bug.go:8: cannot use y (type int) as type C.unsignedshort in assignment

@mdempsky
Copy link
Member

Comparing the names in cmd/cgo/gcc.go:dwarfToName and https://github.com/llvm-mirror/clang/blob/master/lib/Basic/TargetInfo.cpp#L107, it looks like the only differences are that Clang uses "short" and "unsigned short" instead of "short int" and "short unsigned int", respectively.

"short" doesn't need to be mapped, so that just leaves "unsigned short".

@ghost
Copy link
Author

ghost commented Nov 25, 2015

10:tornago hydroflame$ go version
go version go1.5 darwin/amd64

OSX 10.11.1

@ghost ghost closed this as completed Nov 25, 2015
@ghost ghost reopened this Nov 25, 2015
@gopherbot
Copy link

CL https://golang.org/cl/17207 mentions this issue.

@golang golang locked and limited conversation to collaborators Nov 27, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants