Skip to content
New issue

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

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

Already on GitHub? # to your account

cmd/cgo: main declared without a prototype #70769

Closed
rittneje opened this issue Dec 11, 2024 · 3 comments
Closed

cmd/cgo: main declared without a prototype #70769

rittneje opened this issue Dec 11, 2024 · 3 comments
Assignees
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. FixPending Issues that have a fix which has not yet been reviewed or submitted. NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@rittneje
Copy link
Contributor

Go version

go version go1.22.10 darwin/amd64

Output of go env in your module/workspace:

GO111MODULE='auto'
GOARCH='amd64'
GOBIN=''
GOCACHE='/tmp/.gocache'
GOENV='/Users/rittneje/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/rittneje/test/pkg/mod'
GONOPROXY='[redacted]'
GONOSUMDB='[redacted]'
GOOS='darwin'
GOPATH='/Users/rittneje/test'
GOPRIVATE='[redacted]'
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/Users/rittneje/go1.22.10'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='local'
GOTOOLDIR='/Users/rittneje/go1.22.10/pkg/tool/darwin_amd64'
GOVCS='[redacted]'
GOVERSION='go1.22.10'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='clang'
CXX='clang++'
CGO_ENABLED='1'
GOMOD='/Users/rittneje/test/src/cgotest/go.mod'
GOWORK='/Users/rittneje/test/go.work'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/kf/kr7_s3xx0l12zbj3jrn082hmzy5gvy/T/go-build3787749113=/tmp/go-build -gno-record-gcc-switches -fno-common'

What did you do?

I am writing an application that uses cgo. For this reason, I want to compile with all warnings as errors.

package main

// #cgo CFLAGS: -Werror -Wall -Wextra -Wpedantic
import "C"

func main() {

}

What did you see happen?

$ go build
# cgotest
_cgo_main.c:2:9: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]

The contents of _cgo_main.c are:

#include <stddef.h>
int main() { return 0; }
void crosscall2(void(*fn)(void*) __attribute__((unused)), void *a __attribute__((unused)), int c __attribute__((unused)), size_t ctxt __attribute__((unused))) { }
size_t _cgo_wait_runtime_init_done(void) { return 0; }
void _cgo_release_context(size_t ctxt __attribute__((unused))) { }
char* _cgo_topofstack(void) { return (char*)0; }
void _cgo_allocate(void *a __attribute__((unused)), int c __attribute__((unused))) { }
void _cgo_panic(void *a __attribute__((unused)), int c __attribute__((unused))) { }
void _cgo_reginit(void) { }
#line 1 "cgo-generated-wrappers"

My understanding is it wants int main(void) instead of int main().

What did you expect to see?

I expected the auto-generated cgo to not trigger any warnings.

@seankhliao seankhliao changed the title cgo: main declared without a prototype cmd/cgo: main declared without a prototype Dec 11, 2024
@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Dec 11, 2024
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/635095 mentions this issue: cmd/cgo: use full prototype for main in C code

@cagedmantis cagedmantis added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Dec 11, 2024
@cagedmantis
Copy link
Contributor

cc @golang/compiler

@ianlancetaylor ianlancetaylor self-assigned this Dec 11, 2024
@ianlancetaylor ianlancetaylor added NeedsFix The path to resolution is known, but the work has not been done. FixPending Issues that have a fix which has not yet been reviewed or submitted. and removed NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Dec 11, 2024
@prattmic prattmic moved this to In Progress in Go Compiler / Runtime Dec 11, 2024
@prattmic prattmic added this to the Go1.25 milestone Dec 11, 2024
@github-project-automation github-project-automation bot moved this from In Progress to Done in Go Compiler / Runtime Dec 11, 2024
@dmitshur dmitshur modified the milestones: Go1.25, Go1.24 Dec 11, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. FixPending Issues that have a fix which has not yet been reviewed or submitted. NeedsFix The path to resolution is known, but the work has not been done.
Projects
Development

No branches or pull requests

7 participants