From fcf12e5a221621f749841055df1d2c2ada3bf844 Mon Sep 17 00:00:00 2001 From: KangJi Date: Thu, 27 Feb 2025 21:17:51 +0900 Subject: [PATCH] cmd/cgo: generated headers are incompatible with the latest C++ standards in MSVC The current cgo-generated headers are not compatible with MSVC when using ISO C++ 17 or later. These headers rely on constructs that are deprecated or removed in newer C++ standards, leading to compilation errors. This issue affects projects using modern C++ versions and requires either downgrading the C++ standard or manually modifying the generated headers. Fixes #71921 --- src/cmd/cgo/out.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/cmd/cgo/out.go b/src/cmd/cgo/out.go index 43c30a2000..2c3f1e06ff 100644 --- a/src/cmd/cgo/out.go +++ b/src/cmd/cgo/out.go @@ -1991,10 +1991,16 @@ typedef size_t GoUintptr; typedef float GoFloat32; typedef double GoFloat64; #ifdef _MSC_VER +#if !defined(__cplusplus) || _MSVC_LANG <= 201402L #include typedef _Fcomplex GoComplex64; typedef _Dcomplex GoComplex128; #else +#include +typedef std::complex GoComplex64; +typedef std::complex GoComplex128; +#endif +#else typedef float _Complex GoComplex64; typedef double _Complex GoComplex128; #endif