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
hydroflame opened this issue Nov 3, 2015 · 5 comments

Comments

@hydroflame
Copy link

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
}

@hydroflame hydroflame 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

This comment has been minimized.

Copy link
Member

commented Nov 25, 2015

@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

This comment has been minimized.

Copy link
Member

commented Nov 25, 2015

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

This comment has been minimized.

Copy link
Member

commented Nov 25, 2015

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".

@hydroflame

This comment has been minimized.

Copy link
Author

commented Nov 25, 2015

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

OSX 10.11.1

@hydroflame hydroflame closed this Nov 25, 2015

@hydroflame hydroflame reopened this Nov 25, 2015

@gopherbot

This comment has been minimized.

Copy link

commented Nov 25, 2015

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

@mdempsky mdempsky closed this in de640d3 Nov 25, 2015

@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
4 participants
You can’t perform that action at this time.