]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
stdatomic.h: Do not define ATOMIC_VAR_INIT for C2x
authorJoseph Myers <joseph@codesourcery.com>
Mon, 12 Sep 2022 14:34:26 +0000 (14:34 +0000)
committerJoseph Myers <joseph@codesourcery.com>
Mon, 12 Sep 2022 14:34:58 +0000 (14:34 +0000)
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.

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.

gcc/ginclude/stdatomic.h
gcc/testsuite/gcc.dg/atomic/c2x-stdatomic-var-init-1.c [new file with mode: 0644]

index 9f2475b739d1061c8bc27419bb9f611979992430..a56ba5d963997de59085f8a4e6803ca7a88e7c1a 100644 (file)
@@ -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 (file)
index 0000000..1978a41
--- /dev/null
@@ -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