Building a testdir created through
  ./gnulib-tool --create-testdir --dir=../testdir5 --with-c++-tests setlocale 
sys_un-h stddef-h
on mingw, I see this compilation error:

x86_64-w64-mingw32-g++ -DHAVE_CONFIG_H -DEXEEXT=\".exe\" -I. -I../../gltests 
-I..  -DGNULIB_STRICT_CHECKING=1 -DIN_GNULIB_TESTS=1 -I. -I../../gltests -I.. 
-I../../gltests/.. -I../gllib -I../../gltests/../gllib 
-D_WIN32_WINNT=_WIN32_WINNT_WINXP -I/usr/local/mingw64/include -Wall -Wno-error 
-Wno-error -g -O2 -MT test-assert-h-c++.o -MD -MP -MF $depbase.Tpo -c -o 
test-assert-h-c++.o ../../gltests/test-assert-h-c++.cc &&\
mv -f $depbase.Tpo $depbase.Po
In file included from 
/usr/lib/gcc/x86_64-w64-mingw32/13/include/c++/x86_64-w64-mingw32/bits/gthr.h:148,
                 from 
/usr/lib/gcc/x86_64-w64-mingw32/13/include/c++/ext/atomicity.h:35,
                 from 
/usr/lib/gcc/x86_64-w64-mingw32/13/include/c++/bits/ios_base.h:39,
                 from /usr/lib/gcc/x86_64-w64-mingw32/13/include/c++/ios:44,
                 from /usr/lib/gcc/x86_64-w64-mingw32/13/include/c++/ostream:40,
                 from 
/usr/lib/gcc/x86_64-w64-mingw32/13/include/c++/iostream:41,
                 from ../../gltests/test-assert-h-c++.cc:26:
/usr/lib/gcc/x86_64-w64-mingw32/13/include/c++/x86_64-w64-mingw32/bits/gthr-default.h:
 In function ‘int __gthread_create(glwthread_thread_struct**, void* (*)(void*), 
void*)’:
/usr/lib/gcc/x86_64-w64-mingw32/13/include/c++/x86_64-w64-mingw32/bits/gthr-default.h:663:36:
 error: cannot convert ‘glwthread_thread_struct**’ to ‘pthread_t*’ {aka ‘long 
long unsigned int*’}
  663 |   return __gthrw_(pthread_create) (__threadid, NULL, __func, __args);
      |                                    ^~~~~~~~~~
      |                                    |
      |                                    glwthread_thread_struct**
...

This #include <bits/gthr.h> is apparently incompatible with the
  --enable-threads=windows
configuration setting (which is the default in testdirs).

There's nothing we can do about it: <bits/gthr.h> expects the <pthread.h>
contents from mingw, not the Gnulib override. As a consequence,
  --enable-threads=windows
cannot be used on mingw, with C++ applications that make use of the C++
standard library.

This patch documents it and works around it in the tests.


2026-06-07  Bruno Haible  <[email protected]>

        tests: Avoid conflict between mingw standard C++ library and Gnulib.
        * doc/multithread.texi (Gnulib multithreading): Document an
        incompatibility.
        * tests/test-assert-h-c++.cc: Skip the standard C++ library on mingw,
        when configured with --enable-threads=windows.
        * tests/test-assert-h-c++2.cc: Likewise.
        * tests/test-endian-c++.cc: Likewise.
        * tests/test-nullptr-c++.cc: Likewise.
        * tests/test-stdalign-h-c++.cc: Likewise.
        * tests/test-stdbit-h-c++.cc: Likewise.
        * tests/test-wchar-h-c++3.cc: Likewise.

diff --git a/doc/multithread.texi b/doc/multithread.texi
index f2fc3146dd..bdf579df83 100644
--- a/doc/multithread.texi
+++ b/doc/multithread.texi
@@ -244,6 +244,8 @@
 @item
 @code{--enable-threads=windows} is supported and is the best choice on
 native Windows platforms (mingw and MSVC).
+Except that on mingw, in C++ mode, use of the standard C++ library
+(@code{<iostream>} etc.) is incompatible with this choice.
 @item
 @code{--enable-threads=isoc} is supported on all platforms that have the
 ISO C multithreading API.  However, @code{--enable-threads=posix} is always
diff --git a/tests/test-assert-h-c++.cc b/tests/test-assert-h-c++.cc
index 1263265f8b..92d5f86451 100644
--- a/tests/test-assert-h-c++.cc
+++ b/tests/test-assert-h-c++.cc
@@ -21,9 +21,11 @@
 
 #include <assert.h>
 
+#if !(defined __MINGW32__ && USE_WINDOWS_THREADS)
 /* Check against conflicts between <assert.h> and the C++ header files.  */
-#include <stddef.h>
-#include <iostream>
+# include <stddef.h>
+# include <iostream>
+#endif
 
 
 static_assert (2 + 2 == 4, "arithmetic does not work");
diff --git a/tests/test-assert-h-c++2.cc b/tests/test-assert-h-c++2.cc
index 81efd9c1dd..516178bc6d 100644
--- a/tests/test-assert-h-c++2.cc
+++ b/tests/test-assert-h-c++2.cc
@@ -19,9 +19,11 @@
 
 #include <cassert>
 
+#if !(defined __MINGW32__ && USE_WINDOWS_THREADS)
 /* Check against conflicts between <cassert> and other C++ header files.  */
-#include <stddef.h>
-#include <iostream>
+# include <stddef.h>
+# include <iostream>
+#endif
 
 
 static_assert (2 + 2 == 4, "arithmetic does not work");
diff --git a/tests/test-endian-c++.cc b/tests/test-endian-c++.cc
index 1058c9c8be..1480b8484d 100644
--- a/tests/test-endian-c++.cc
+++ b/tests/test-endian-c++.cc
@@ -21,9 +21,11 @@
 
 #include <endian.h>
 
+#if !(defined __MINGW32__ && USE_WINDOWS_THREADS)
 /* Check against conflicts between <endian.h> and the C++ header files.  */
-#include <stddef.h>
-#include <iostream>
+# include <stddef.h>
+# include <iostream>
+#endif
 
 
 int
diff --git a/tests/test-nullptr-c++.cc b/tests/test-nullptr-c++.cc
index 09f977e8ac..ad2449e582 100644
--- a/tests/test-nullptr-c++.cc
+++ b/tests/test-nullptr-c++.cc
@@ -21,9 +21,11 @@
 /* Check that nullptr is defined.  */
 int *my_null = nullptr;
 
+#if !(defined __MINGW32__ && USE_WINDOWS_THREADS)
 /* Check against conflicts between <config.h> and the C++ header files.  */
-#include <iostream>
-#include <vector>
+# include <iostream>
+# include <vector>
+#endif
 
 #include <stdarg.h>
 
diff --git a/tests/test-stdalign-h-c++.cc b/tests/test-stdalign-h-c++.cc
index 7093ec6663..7cf4f86106 100644
--- a/tests/test-stdalign-h-c++.cc
+++ b/tests/test-stdalign-h-c++.cc
@@ -21,9 +21,11 @@
 
 #include <stdalign.h>
 
+#if !(defined __MINGW32__ && USE_WINDOWS_THREADS)
 /* Check against conflicts between <stdalign.h> and the C++ header files.  */
-#include <stddef.h>
-#include <iostream>
+# include <stddef.h>
+# include <iostream>
+#endif
 
 
 int
diff --git a/tests/test-stdbit-h-c++.cc b/tests/test-stdbit-h-c++.cc
index cf84f4bb7e..6dc14860e2 100644
--- a/tests/test-stdbit-h-c++.cc
+++ b/tests/test-stdbit-h-c++.cc
@@ -21,9 +21,11 @@
 
 #include <stdbit.h>
 
+#if !(defined __MINGW32__ && USE_WINDOWS_THREADS)
 /* Check against conflicts between <stdbit.h> and the C++ header files.  */
-#include <stddef.h>
-#include <iostream>
+# include <stddef.h>
+# include <iostream>
+#endif
 
 
 int
diff --git a/tests/test-wchar-h-c++3.cc b/tests/test-wchar-h-c++3.cc
index 279f827faf..0a0f1b68a7 100644
--- a/tests/test-wchar-h-c++3.cc
+++ b/tests/test-wchar-h-c++3.cc
@@ -18,5 +18,7 @@
 #include <config.h>
 
 #include <wchar.h>
-#include <cstring>
-#include <sstream>
+#if !(defined __MINGW32__ && USE_WINDOWS_THREADS)
+# include <cstring>
+# include <sstream>
+#endif




Reply via email to