golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
123.99k stars 17.67k forks source link

cmd/cgo: _GoString_ is a reserved identifier #29877

Open phst opened 5 years ago

phst commented 5 years ago

(Removing the template since this is not really a code bug or so.)

https://golang.org/cmd/cgo/#hdr-Go_references_to_C explains that there's a type _GoString_. However, that name is reserved (see https://en.cppreference.com/w/c/language/identifier#Reserved_identifiers), and using it is technically undefined behavior. I'd suggest renaming the type to just GoString in future versions, with the old name as undocumented and deprecated alias.

phst commented 5 years ago

This is also the case for most other Cgo names in C.

phst commented 5 years ago

If you're fine with renaming all the Cgo identifiers, I can take this.

ianlancetaylor commented 5 years ago

Renaming all the cgo identifiers seems likely to break existing code. I'm not sure exactly what we can do here.

phst commented 5 years ago

From skimming https://golang.org/cmd/cgo/, _GoString_ and the associated functions seem to be the only documented ones. I'd suggest we rename them, but provide aliases/forwarding functions marked as deprecated. If we don't care about breakages caused by using the undocumented names, we can just rename them.

ianlancetaylor commented 5 years ago

Do you happen to have a list of the undocumented names that are invalid according to the C standard?

Unfortunately history tells us that many people write code that refers to undocumented cgo names.

I'm OK with renaming GoString in the docs as long it continues to work in the code.