Building a testdir created through

  $ ./gnulib-tool --create-testdir --dir=../testdir4 --with-c++-tests 
stdckdint-h

on MSVC, I get this syntax error:

/cygdrive/d/a/ci-scratch/ci-scratch/compile cl -nologo -DHAVE_CONFIG_H -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/msvc64/include 
-DCONTINUE_AFTER_ASSERT  -MD -c -o test-stdckdint-h-c++.obj `cygpath -w 
'../../gltests/test-stdckdint-h-c++.cc'`
test-stdckdint-h-c++.cc
D:\a\ci-scratch\ci-scratch\testdir57\gltests\test-stdckdint-h-c++.cc(33): error 
C3861: '__typeof__': identifier not found
D:\a\ci-scratch\ci-scratch\testdir57\gltests\test-stdckdint-h-c++.cc(33): error 
C2059: syntax error: 'constant'
make[4]: *** [Makefile:1802: test-stdckdint-h-c++.obj] Error 2

This patch fixes it.


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

        intprops, stdbit-h: Fix error on MSVC in C++ mode (regr. 2024-12-19).
        * lib/intprops-internal.h (_GL_HAVE___TYPEOF__): Set to 0 on MSVC in
        C++ mode.
        * lib/stdbit.in.h (_GL_STDBIT_TYPEOF_CAST): Don't use __typeof__ on MSVC
        in C++ mode.

diff --git a/lib/intprops-internal.h b/lib/intprops-internal.h
index 1fb3b79901..4055173dc8 100644
--- a/lib/intprops-internal.h
+++ b/lib/intprops-internal.h
@@ -106,7 +106,7 @@
      || (defined __clang_major__ && 4 <= __clang_major__) \
      || (defined __IBMC__ && 1210 <= __IBMC__ && defined __IBM__TYPEOF__) \
      || (defined __SUNPRO_C && 0x5110 <= __SUNPRO_C && !__STDC__) \
-     || (defined _MSC_VER && 1939 <= _MSC_VER))
+     || (defined _MSC_VER && 1939 <= _MSC_VER && !defined __cplusplus))
 # define _GL_HAVE___TYPEOF__ 1
 #else
 # define _GL_HAVE___TYPEOF__ 0
diff --git a/lib/stdbit.in.h b/lib/stdbit.in.h
index 92749487fa..c7047e3297 100644
--- a/lib/stdbit.in.h
+++ b/lib/stdbit.in.h
@@ -175,7 +175,7 @@ _GL_INLINE_HEADER_BEGIN
      || (defined __clang_major__ && 4 <= __clang_major__) \
      || (defined __IBMC__ && 1210 <= __IBMC__ && defined __IBM__TYPEOF__) \
      || (defined __SUNPRO_C && 0x5110 <= __SUNPRO_C && !__STDC__) \
-     || (defined _MSC_VER && 1939 <= _MSC_VER))
+     || (defined _MSC_VER && 1939 <= _MSC_VER && !defined __cplusplus))
 # define _GL_STDBIT_TYPEOF_CAST(a, b) ((__typeof__ (a)) (b))
 #elif 202311 <= __STDC_VERSION__
 # define _GL_STDBIT_TYPEOF_CAST(a, b) ((typeof (a)) (b))




Reply via email to