Building a testdir for module 'regex' on the GitHub CI machines, I see
a compilation error in the MSVC build:
../../gllib\regex.h(671): error C2143: syntax error: missing ']' before
'restrict'
../../gllib\regex.h(671): error C2143: syntax error: missing ')' before
'restrict'
../../gllib\regex.h(671): error C2143: syntax error: missing '{' before
'restrict'
../../gllib\regex.h(671): error C2219: syntax error: type qualifier must be
after '*'
../../gllib\regex.h(671): error C2059: syntax error: ']'
../../gllib\regex.h(672): error C2059: syntax error: ')'
make[4]: *** [Makefile:2860: regex.obj] Error 2
The compiler version is MSVC 14.44.35207, a.k.a. MSVC 2022.
This patch fixes it.
2026-05-06 Bruno Haible <[email protected]>
regex: Fix compilation error with MSVC 2022.
* lib/cdefs.h (__restrict_arr): On MSVC, ignore __STDC_VERSION__.
* lib/regex.h (_Restrict_arr_): Likewise.
diff --git a/lib/cdefs.h b/lib/cdefs.h
index 42024b20e1..2800057cb7 100644
--- a/lib/cdefs.h
+++ b/lib/cdefs.h
@@ -669,7 +669,8 @@
# ifdef __GNUC__
# define __restrict_arr /* Not supported in old GCC. */
# else
-# if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L
+# if (defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L \
+ && !defined _MSC_VER)
# define __restrict_arr restrict
# else
/* Some other non-C99 compiler. */
diff --git a/lib/regex.h b/lib/regex.h
index df35c93e5a..152a157c2f 100644
--- a/lib/regex.h
+++ b/lib/regex.h
@@ -645,15 +645,15 @@ extern int re_exec (const char *);
array_name[restrict]
use glibc's __restrict_arr if available.
Otherwise, GCC 3.1 and clang support this syntax (but not in C++ mode).
- Other ISO C99 compilers support it as well. */
+ Other ISO C99 compilers support it as well, except for MSVC. */
#ifndef _Restrict_arr_
# ifdef __restrict_arr
# define _Restrict_arr_ __restrict_arr
# else
-# if ((199901L <= __STDC_VERSION__ \
- || 3 < __GNUC__ + (1 <= __GNUC_MINOR__) \
- || __clang_major__ >= 3) \
- && !defined __cplusplus)
+# if (((199901L <= __STDC_VERSION__ && !defined _MSC_VER) \
+ || 3 < __GNUC__ + (1 <= __GNUC_MINOR__) \
+ || __clang_major__ >= 3) \
+ && !defined __cplusplus)
# define _Restrict_arr_ _Restrict_
# else
# define _Restrict_arr_