public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* stdatomic.h: Do not define ATOMIC_VAR_INIT for C2x
@ 2022-09-09 20:41 Joseph Myers
  2022-09-12  7:28 ` Richard Biener
  0 siblings, 1 reply; 2+ messages in thread
From: Joseph Myers @ 2022-09-09 20:41 UTC (permalink / raw)
  To: gcc-patches

The <stdatomic.h> macro ATOMIC_VAR_INIT, previously declared obsolete,
is removed completely in C2x; disable it for C2x in GCC's
implementation.  (Although ATOMIC_* are reserved names for this
header, disabling the macro for C2x still seems appropriate.)

Bootstrapped with no regressions for x86_64-pc-linux-gnu.  OK to commit?

gcc/
	* ginclude/stdatomic.h [defined __STDC_VERSION__ &&
	__STDC_VERSION__ > 201710L] (ATOMIC_VAR_INIT): Do not define.

gcc/testsuite/
	* gcc.dg/atomic/c2x-stdatomic-var-init-1.c: New test.

diff --git a/gcc/ginclude/stdatomic.h b/gcc/ginclude/stdatomic.h
index 9f2475b739d..a56ba5d9639 100644
--- a/gcc/ginclude/stdatomic.h
+++ b/gcc/ginclude/stdatomic.h
@@ -79,7 +79,9 @@ typedef _Atomic __INTMAX_TYPE__ atomic_intmax_t;
 typedef _Atomic __UINTMAX_TYPE__ atomic_uintmax_t;        
 
 
+#if !(defined __STDC_VERSION__ && __STDC_VERSION__ > 201710L)
 #define ATOMIC_VAR_INIT(VALUE)	(VALUE)
+#endif
 
 /* Initialize an atomic object pointed to by PTR with VAL.  */
 #define atomic_init(PTR, VAL)                           \
diff --git a/gcc/testsuite/gcc.dg/atomic/c2x-stdatomic-var-init-1.c b/gcc/testsuite/gcc.dg/atomic/c2x-stdatomic-var-init-1.c
new file mode 100644
index 00000000000..1978a410350
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/atomic/c2x-stdatomic-var-init-1.c
@@ -0,0 +1,9 @@
+/* Test ATOMIC_VAR_INIT not in C2x.  */
+/* { dg-do compile } */
+/* { dg-options "-std=c2x -pedantic-errors" } */
+
+#include <stdatomic.h>
+
+#ifdef ATOMIC_VAR_INIT
+#error "ATOMIC_VAR_INIT defined"
+#endif

-- 
Joseph S. Myers
joseph@codesourcery.com

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: stdatomic.h: Do not define ATOMIC_VAR_INIT for C2x
  2022-09-09 20:41 stdatomic.h: Do not define ATOMIC_VAR_INIT for C2x Joseph Myers
@ 2022-09-12  7:28 ` Richard Biener
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2022-09-12  7:28 UTC (permalink / raw)
  To: Joseph Myers; +Cc: GCC Patches

On Fri, Sep 9, 2022 at 10:41 PM Joseph Myers <joseph@codesourcery.com> wrote:
>
> The <stdatomic.h> macro ATOMIC_VAR_INIT, previously declared obsolete,
> is removed completely in C2x; disable it for C2x in GCC's
> implementation.  (Although ATOMIC_* are reserved names for this
> header, disabling the macro for C2x still seems appropriate.)
>
> Bootstrapped with no regressions for x86_64-pc-linux-gnu.  OK to commit?

OK

> gcc/
>         * ginclude/stdatomic.h [defined __STDC_VERSION__ &&
>         __STDC_VERSION__ > 201710L] (ATOMIC_VAR_INIT): Do not define.
>
> gcc/testsuite/
>         * gcc.dg/atomic/c2x-stdatomic-var-init-1.c: New test.
>
> diff --git a/gcc/ginclude/stdatomic.h b/gcc/ginclude/stdatomic.h
> index 9f2475b739d..a56ba5d9639 100644
> --- a/gcc/ginclude/stdatomic.h
> +++ b/gcc/ginclude/stdatomic.h
> @@ -79,7 +79,9 @@ typedef _Atomic __INTMAX_TYPE__ atomic_intmax_t;
>  typedef _Atomic __UINTMAX_TYPE__ atomic_uintmax_t;
>
>
> +#if !(defined __STDC_VERSION__ && __STDC_VERSION__ > 201710L)
>  #define ATOMIC_VAR_INIT(VALUE) (VALUE)
> +#endif
>
>  /* Initialize an atomic object pointed to by PTR with VAL.  */
>  #define atomic_init(PTR, VAL)                           \
> diff --git a/gcc/testsuite/gcc.dg/atomic/c2x-stdatomic-var-init-1.c b/gcc/testsuite/gcc.dg/atomic/c2x-stdatomic-var-init-1.c
> new file mode 100644
> index 00000000000..1978a410350
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/atomic/c2x-stdatomic-var-init-1.c
> @@ -0,0 +1,9 @@
> +/* Test ATOMIC_VAR_INIT not in C2x.  */
> +/* { dg-do compile } */
> +/* { dg-options "-std=c2x -pedantic-errors" } */
> +
> +#include <stdatomic.h>
> +
> +#ifdef ATOMIC_VAR_INIT
> +#error "ATOMIC_VAR_INIT defined"
> +#endif
>
> --
> Joseph S. Myers
> joseph@codesourcery.com

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-09-12  7:28 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-09 20:41 stdatomic.h: Do not define ATOMIC_VAR_INIT for C2x Joseph Myers
2022-09-12  7:28 ` Richard Biener

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).