From: Paul Eggert Date: Sat, 9 May 2026 22:04:28 +0000 (-0700) Subject: Fix ‘restrict’ on MSVC and on Solaris 11.4 g++ X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d869a48423913f723b1cf605e807be2dbe279c88;p=thirdparty%2Fautoconf.git Fix ‘restrict’ on MSVC and on Solaris 11.4 g++ Problem and fix reported by Bruno Haible in: https://lists.gnu.org/r/bug-gnulib/2026-05/msg00069.html * lib/autoconf/c.m4 (AC_C_RESTRICT): Ignore the value of __STDC_VERSION__ on MSVC or in C++ mode. --- diff --git a/doc/autoconf.texi b/doc/autoconf.texi index 70fcf2438..84dd473b7 100644 --- a/doc/autoconf.texi +++ b/doc/autoconf.texi @@ -7599,7 +7599,7 @@ If the C compiler supports C11-style generic selection using the @caindex c_restrict If the C compiler recognizes a variant spelling for the @code{restrict} keyword (@code{__restrict}, @code{__restrict__}, or @code{_Restrict}), -then define @code{restrict} to that for both C++ and pre-C99 C; +then define @code{restrict} to that for both C++ and non-C99 C; this is more likely to do the right thing with compilers that support language variants where plain @code{restrict} is not a keyword. Otherwise, if the C compiler diff --git a/lib/autoconf/c.m4 b/lib/autoconf/c.m4 index f386d0245..07542d1a1 100644 --- a/lib/autoconf/c.m4 +++ b/lib/autoconf/c.m4 @@ -2172,7 +2172,7 @@ fi # # Determine whether the C/C++ compiler supports the "restrict" keyword # introduced in ANSI C99, or an equivalent. Define "restrict" to the alternate -# spelling, if any, in pre-C99 C and in C++; this should work in compilers of +# spelling, if any, in non-C99 C and in C++; this should work in compilers of # the same family, and in the presence of varying compiler options. If only # plain "restrict" works, do nothing. Here are some variants: # - GCC-compatible compilers support both __restrict and __restrict__ @@ -2205,9 +2205,12 @@ AC_DEFUN([AC_C_RESTRICT], ]) AH_VERBATIM([restrict], [/* Define to the equivalent of the C99 'restrict' keyword, or to - nothing if this is not supported. Do not define if restrict is - supported directly. */ -#if ! (defined __STDC_VERSION__ && 199901L <= __STDC_VERSION__) + nothing if this is not supported. In particular it is not supported + in MSVC 14.44 and in g++ 7 on Solaris 11, although these compilers + define __STDC_VERSION__ to 199901L. + Do not define if restrict is supported directly. */ +#if ! (defined __STDC_VERSION__ && 199901L <= __STDC_VERSION__ \ + && !defined _MSC_VER && !defined __cplusplus) #undef restrict #endif /* Work around a bug in older versions of Sun C++, which did not @@ -2309,7 +2312,7 @@ AC_DEFUN([AC_C_FLEXIBLE_ARRAY_MEMBER], [Define to nothing if C supports flexible array members, and to 1 if it does not. That way, with a declaration like 'struct s { int n; double d@<:@FLEXIBLE_ARRAY_MEMBER@:>@; };', the struct hack - can be used with pre-C99 compilers. + can be used with non-C99 C compilers. When computing the size of such an object, don't use 'sizeof (struct s)' as it overestimates the size. Use 'offsetof (struct s, d)' instead. Don't use 'offsetof (struct s, d@<:@0@:>@)', as this doesn't work with