Hi,
When building a test package shared in
https://savannah.gnu.org/bugs/?57406
(https://haible.de/bruno/gnu/testdir-posix-mingw.tar.gz) with my
mingw/clang/libc++ based toolchain, I ran into some errors in the gltests
subdirectory.
One of the errors looks like this:
In file included from test-arpa_inet-c++.cc:22:
In file included from ../gllib/arpa/inet.h:34:
In file included from ../gllib/sys/socket.h:651:
In file included from /toolchain/x86_64-w64-mingw32/include/winsock2.h:23:
In file included from /toolchain/x86_64-w64-mingw32/include/windows.h:69:
In file included from /toolchain/x86_64-w64-mingw32/include/windef.h:8:
In file included from /toolchain/x86_64-w64-mingw32/include/minwindef.h:167:
In file included from /toolchain/x86_64-w64-mingw32/include/winnt.h:1554:
In file included from /toolchain/lib/clang/10.0.0/include/x86intrin.h:15:
In file included from /toolchain/lib/clang/10.0.0/include/immintrin.h:18:
In file included from /toolchain/lib/clang/10.0.0/include/xmmintrin.h:27:
In file included from /toolchain/lib/clang/10.0.0/include/mm_malloc.h:13:
In file included from ../gllib/stdlib.h:36:
In file included from /toolchain/x86_64-w64-mingw32/include/c++/v1/stdlib.h:100:
../gllib/math.h:2740:46: error: conflicting types for 'rpl_isfinite'
_GL_MATH_CXX_REAL_FLOATING_DECL_2 (isfinite, rpl_isfinite, bool)
^
../gllib/math.h:2740:46: note: previous definition is here
../gllib/math.h:2740:46: error: conflicting types for 'rpl_isfinite'
_GL_MATH_CXX_REAL_FLOATING_DECL_2 (isfinite, rpl_isfinite, bool)
For various reasons, gnulib decides to replace the isfinite function, and
then the gnulib math.h file provides C++ overloaded functions for
different data types.
In this particular case, this math.h header ends up included in a context
wrapped in 'extern "C" {}' surrounding it, which breaks the C++ function
overloading.
The series of headers leading up to this is a bit long...
- The source file includes some windows header
- windef.h includes winnt.h within an extern "C" block. windef.h also
includes minwindef.h, which also includes winnt.h within an extern "C"
block. Not sure if this really is the right thing to do or not.
- The mingw-w64 winnt.h has one extern "C" block covering the whole file,
one over a section of the file, and one block specifically around an
include of x86intrin.h. Not sure if the former two are right, but
x86intrin.h and the files that it includes at least seem like they
really need extern "C" around them.
- *intrinh end up including mm_malloc.h (this also goes for gcc), and
mm_malloc.h includes stdlib.h (also goes for gcc)
- libc++'s stdlib.h (which is included before the normal stdlib.h)
includes math.h since https://reviews.llvm.org/D60097 (this was also the
root cause for an issue discussed earlier), and math.h (which first hits
gnulib's math.h) now tries to declare the overloaded set of
float/double/long double rpl_isfinite functions, which fails since
we're in an extern "C" scope.
I'm not really sure which bit in this chain that actually can be
considered wrong, but I wanted to post the issue I'm seeing at least...
libc++'s math.h should in principle also have the same issue (if just
including windows.h in a C++ file), but it seems to be using some other
mechanism for its function overloads, which makes it not break apart here.
// Martin