]> git.ipfire.org Git - thirdparty/autoconf.git/commitdiff
Fix ‘restrict’ on MSVC and on Solaris 11.4 g++
authorPaul Eggert <eggert@cs.ucla.edu>
Sat, 9 May 2026 22:04:28 +0000 (15:04 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Sat, 9 May 2026 22:06:16 +0000 (15:06 -0700)
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.

doc/autoconf.texi
lib/autoconf/c.m4

index 70fcf24384c4c70a461d624f354df72d30f89db2..84dd473b7824fd32eb8674cbe14db7e074287a0e 100644 (file)
@@ -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
index f386d02450524877595c7e94cf1ff241ed0827c6..07542d1a13490ba5f94d81d9716d880bd7176c0d 100644 (file)
@@ -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