public inbox for newlib@sourceware.org
 help / color / mirror / Atom feed
From: Corinna Vinschen <vinschen@redhat.com>
To: Sebastian Huber <sebastian.huber@embedded-brains.de>
Cc: newlib@sourceware.org
Subject: Re: [PATCH 2/2] sys/cdefs.h: fix for use __restrict in C++
Date: Mon, 7 Aug 2023 15:15:49 +0200	[thread overview]
Message-ID: <ZNDuhfUHF3RDE+P2@calimero.vinschen.de> (raw)
In-Reply-To: <20230807092825.24459-3-sebastian.huber@embedded-brains.de>

Hi Sebastian,

On Aug  7 11:28, Sebastian Huber wrote:
> diff --git a/newlib/libc/include/sys/cdefs.h b/newlib/libc/include/sys/cdefs.h
> index 808498c50b..cc1a8a1ccb 100644
> --- a/newlib/libc/include/sys/cdefs.h
> +++ b/newlib/libc/include/sys/cdefs.h
> @@ -412,17 +412,15 @@
>  #endif
>  
>  /*
> - * 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.
> + * We use `__restrict' as a way to define the `restrict' type qualifier
> + * without disturbing older software that is unaware of C99 keywords.
> + * GCC also provides `__restrict' as an extension to support C99-style
> + * restricted pointers in other language modes.
>   */
> -#if !(__GNUC__ == 2 && __GNUC_MINOR__ == 95)
> -#if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901
> -#define	__restrict
> -#else
> +#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901
>  #define	__restrict	restrict
> -#endif
> +#elif !__GNUC_PREREQ__(2, 95)
> +#define	__restrict
>  #endif
>  
>  /*

Turns out, this leads to a build failuer in Cygwin.

We have a definition in aio.h:

  int lio_listio (int, struct aiocb *__restrict const [__restrict], int,
		  struct sigevent *__restrict);

and a matching one in aio.cc:

  int 
  lio_listio (int mode, struct aiocb *__restrict const aiolist[__restrict],
              int nent, struct sigevent *__restrict sig)

The problem is the bracket expression.  The restrict keyword is allowed
in C90, but not in C++.

GLibc has a special definition __restrict_arr in cdefs.h, which is used
in the brackets of the above definition:

  /* ISO C99 also allows to declare arrays as non-overlapping.  The syntax is
       array_name[restrict]
     GCC 3.1 and clang support this.
     This syntax is not usable in C++ mode.  */
  #if (__GNUC_PREREQ (3,1) || __clang_major__ >= 3) && !defined __cplusplus
  # define __restrict_arr __restrict
  #else
  # ifdef __GNUC__
  #  define __restrict_arr        /* Not supported in old GCC.  */
  # else
  #  if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L
  #   define __restrict_arr       restrict
  #  else 
  /* Some other non-C99 compiler.  */
  #   define __restrict_arr       /* Not supported.  */
  #  endif
  # endif
  #endif  

This doesn't exist in FreeBSD, though.

Do you think it's ok to add it to our cdefs.h, nevertheless?


Thanks,
Corinna


  reply	other threads:[~2023-08-07 13:15 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-07  9:28 [PATCH 0/2] Synchronize <sys/cdefs.h> with FreeBSD Sebastian Huber
2023-08-07  9:28 ` [PATCH 1/2] <sys/cdefs.h>: Decay expression passed to fallback version of __generic() Sebastian Huber
2023-08-07  9:28 ` [PATCH 2/2] sys/cdefs.h: fix for use __restrict in C++ Sebastian Huber
2023-08-07 13:15   ` Corinna Vinschen [this message]
2023-08-07 13:35     ` Sebastian Huber
2023-08-07 14:10       ` Corinna Vinschen
2023-08-07 10:00 ` [PATCH 0/2] Synchronize <sys/cdefs.h> with FreeBSD Corinna Vinschen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZNDuhfUHF3RDE+P2@calimero.vinschen.de \
    --to=vinschen@redhat.com \
    --cc=newlib@sourceware.org \
    --cc=sebastian.huber@embedded-brains.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).