Compiling a gnulib testdir with recent MSVC, I also see these errors: C:\cygwin64\home\bruno\testdir-all-for-mingw\gltests\test-call_once2.c(123): error C2440: 'type cast': cannot convert from 'thrd_t' to 'void *' ... C:\cygwin64\home\bruno\testdir-all-for-mingw\gltests\test-mtx.c(124): error C2440: 'type cast': cannot convert from 'thrd_t' to 'void *' ... C:\cygwin64\home\bruno\testdir-all-for-mingw\gltests\test-thread_local.c(98): error C2440: 'type cast': cannot convert from 'thrd_t' to 'void *' ... C:\cygwin64\home\bruno\testdir-all-for-mingw\gltests\test-tss.c(94): error C2440: 'type cast': cannot convert from 'thrd_t' to 'void *'
The cause is that this implementation's thrd_t is a struct. This patch fixes the errors. 2026-10-17 Bruno Haible <[email protected]> tests: Fix some compilation errors with recent MSVC. * tests/test-call_once2.c (thrd_current_pointer): Define differently for MSVC with <threads.h>. * tests/test-mtx.c (thrd_current_pointer): Likewise. * tests/test-thread_local.c (thrd_current_pointer): Likewise. * tests/test-tss.c (thrd_current_pointer): Likewise. diff --git a/tests/test-call_once2.c b/tests/test-call_once2.c index 86a0517906..270fc4c306 100644 --- a/tests/test-call_once2.c +++ b/tests/test-call_once2.c @@ -71,6 +71,9 @@ The first three bytes of this field appear to uniquely identify a pthread_t, though not necessarily representing a pointer. */ # define thrd_current_pointer() (*((void **) thrd_current ().__)) +#elif defined _MSC_VER && HAVE_THREADS_H + /* In MSVC 17.8 (2022) or newer, thrd_t is a struct with a _Handle field. */ +# define thrd_current_pointer() (thrd_current ()._Handle) #elif defined __sun /* On Solaris, thrd_t is merely an 'unsigned int'. */ # define thrd_current_pointer() ((void *) (uintptr_t) thrd_current ()) diff --git a/tests/test-mtx.c b/tests/test-mtx.c index 593f1366ea..b6f69c7ab0 100644 --- a/tests/test-mtx.c +++ b/tests/test-mtx.c @@ -76,6 +76,9 @@ The first three bytes of this field appear to uniquely identify a pthread_t, though not necessarily representing a pointer. */ # define thrd_current_pointer() (*((void **) thrd_current ().__)) +#elif defined _MSC_VER && HAVE_THREADS_H + /* In MSVC 17.8 (2022) or newer, thrd_t is a struct with a _Handle field. */ +# define thrd_current_pointer() (thrd_current ()._Handle) #elif defined __sun /* On Solaris, thrd_t is merely an 'unsigned int'. */ # define thrd_current_pointer() ((void *) (uintptr_t) thrd_current ()) diff --git a/tests/test-thread_local.c b/tests/test-thread_local.c index 569ad4cf3d..6ba03e02fd 100644 --- a/tests/test-thread_local.c +++ b/tests/test-thread_local.c @@ -64,6 +64,9 @@ The first three bytes of this field appear to uniquely identify a pthread_t, though not necessarily representing a pointer. */ # define thrd_current_pointer() (*((void **) thrd_current ().__)) +#elif defined _MSC_VER && HAVE_THREADS_H + /* In MSVC 17.8 (2022) or newer, thrd_t is a struct with a _Handle field. */ +# define thrd_current_pointer() (thrd_current ()._Handle) #elif defined __sun /* On Solaris, thrd_t is merely an 'unsigned int'. */ # define thrd_current_pointer() ((void *) (uintptr_t) thrd_current ()) diff --git a/tests/test-tss.c b/tests/test-tss.c index 0a2ba1afae..ceb4626bbb 100644 --- a/tests/test-tss.c +++ b/tests/test-tss.c @@ -56,6 +56,9 @@ The first three bytes of this field appear to uniquely identify a pthread_t, though not necessarily representing a pointer. */ # define thrd_current_pointer() (*((void **) thrd_current ().__)) +#elif defined _MSC_VER && HAVE_THREADS_H + /* In MSVC 17.8 (2022) or newer, thrd_t is a struct with a _Handle field. */ +# define thrd_current_pointer() (thrd_current ()._Handle) #elif defined __sun /* On Solaris, thrd_t is merely an 'unsigned int'. */ # define thrd_current_pointer() ((void *) (uintptr_t) thrd_current ())
