]> Cypherpunks.ru repositories - gostls13.git/commit
cmd/go: cgo export header to be compatible with MSVC complex types
authorqmuntal <quimmuntal@gmail.com>
Thu, 31 Mar 2022 12:15:22 +0000 (14:15 +0200)
committerGopher Robot <gobot@golang.org>
Fri, 8 Apr 2022 14:13:32 +0000 (14:13 +0000)
commit3e387528e54971d6009fe8833dcab6fc08737e04
tree13a4bbec21152ea3ea02d8e227c8b7c4a1e1d33b
parent3e7ffb862f550c38ce0611b970a4dce10a01226e
cmd/go: cgo export header to be compatible with MSVC complex types

After CL 379474 has landed, the only remaining cgo export header
incompatibility with MSVC is the use of the _Complex macro,
which is not supported in MSVC even when it is part of the ISO C99
standard (1).

Since MSVC 2015 (2), complex math are supported via _Fcomplex and
_Dcomplex, which are equivalent to float _Complex and double _Complex.

As MSVC and C complex types have the same memory layout, we should
be able to typedef GoComplex64 and GoComplex128 to the appropriate
type in MSVC.

It is important to note that this CL is not adding MSVC support to cgo.
C compilers should still be GCC-compatible.

This CL is about allowing to include, without further modifications,
a DLL export header generated by cgo, normally using Mingw-W64 compiler,
into a MSVC project. This was already possible if the export header
changes introduced in this CL were done outside cgo, either manually or
in a post-build script.

Fixes #36233

1: https://docs.microsoft.com/en-us/cpp/c-runtime-library/complex-math-support
2: https://docs.microsoft.com/en-us/cpp/overview/visual-cpp-language-conformance?c-standard-library-features-1
Change-Id: Iad8f26984b115c728e3b73f3a8334ade7a11cfa1
Reviewed-on: https://go-review.googlesource.com/c/go/+/397134
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Trust: Cherry Mui <cherryyz@google.com>
Run-TryBot: Cherry Mui <cherryyz@google.com>
Auto-Submit: Cherry Mui <cherryyz@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
misc/cgo/testcshared/cshared_test.go
misc/cgo/testcshared/testdata/issue36233/issue36233.go [new file with mode: 0644]
src/cmd/cgo/out.go