Skip to content

cmd/cgo: C functions that return void incorrectly return Go values #21878

Open
@bcmills

Description

@bcmills

cgo fails to reject the following program — despite numerous errors involving values of type C.void, which ought to be completely uninstantiable. (The word “void” itself means “empty”, so it's nonsensical for the type “void” to contain a value!)

I'm not sure to what extent this is fixable, given that the fix for #3729 added a test verifying that Go callers can bind _, err to the result of a call to a void-returning function.

package p

/*
static void return_void() { return; }
*/
import "C"

func F() {
	x := C.return_void() // ERROR HERE
	var y C.void = x     // ERROR HERE
	var z *C.void = &y   // ERROR HERE
	var b [0]byte = *z   // ERROR HERE
	_ = b
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.compiler/runtimeIssues related to the Go compiler and/or runtime.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions