4
0
mirror of git://sourceware.org/git/newlib-cygwin.git synced 2025-03-06 06:56:00 +08:00
Sebastian Huber 3c75fac130 sys/cdefs.h: fix for use __restrict in C++
Newlib shares large parts of <sys/cdefs.h> with FreeBSD and received
this bug report:

https://sourceware.org/pipermail/newlib/2023/020400.html

As an extension, GCC and clang offer C99-style restricted pointers in
C++ mode:
https://gcc.gnu.org/onlinedocs/gcc/Restricted-Pointers.html

We notice that this extension is broken when including newlib headers:
restricted pointers are treated as ordinary pointers.

We traced this to the following section of
newlib/libc/include/sys/cdefs.h:

  /*
   * GCC 2.95 provides `__restrict' as an extension to C90 to support the
   * C99-specific `restrict' type qualifier.  We happen to use `__restrict' as
   * a way to define the `restrict' type qualifier without disturbing older
   * software that is unaware of C99 keywords.
   */
  #if !(__GNUC__ == 2 && __GNUC_MINOR__ == 95)
  #if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901
  #define	__restrict
  #else
  #define	__restrict	restrict
  #endif
  #endif

While the GCC __restrict extension was indeed introduced in GCC 2.95, it
is not limited to this version; the extension is also not limited to
C90:
https://gcc.gnu.org/gcc-2.95/c++features.html

Rewrite the logic in the header so that __restrict is kept alone when
available.

PR:	272723
MFC after:	1 week
2023-08-07 13:45:21 +02:00
..
2019-11-04 07:03:15 +01:00
2018-01-17 11:47:17 -06:00
2022-09-26 13:44:21 -04:00
2023-06-21 15:15:03 +02:00
2022-05-29 17:45:52 -04:00
2018-01-17 11:47:17 -06:00
2018-01-17 11:47:13 -06:00
2021-11-15 19:32:23 -05:00
2022-05-29 17:45:52 -04:00
2021-11-15 19:32:23 -05:00