]> sourceware.org Git - newlib-cygwin.git/commitdiff
sys/stdatomic.h: be nicer to c++
authorKonstantin Belousov <kib@FreeBSD.org>
Sun, 27 Mar 2022 21:16:15 +0000 (00:16 +0300)
committerSebastian Huber <sebastian.huber@embedded-brains.de>
Tue, 9 Jul 2024 06:20:50 +0000 (08:20 +0200)
Use of stdatomic.h is undefined in C++, even the C++ 2020 standard does not
list stdatomic.h as a C library header supported by the language.  More,
there are some subtle differences between the <atomic> C++ header, and
C11+ stdatomic.h provided features.

Nonetheless, it is a quality of the implementation aspect, so let mis-users
mis-use stdatomic.h as they want, by making a compat shim for _Bool.

PR: 262683
Reported by: yuri
Reviewed by: dim, emaste
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Differential revision: https://reviews.freebsd.org/D34686

newlib/libc/include/stdatomic.h

index f62ae7b6a7782a40da5e16648e2dbf15a358d8f2..1acec53c007f479ed4b8e7109b5f7107a390ab10 100644 (file)
@@ -163,6 +163,11 @@ atomic_signal_fence(memory_order __order __unused)
 #endif
 }
 
+#if defined(__cplusplus) && !defined(_Bool)
+#define        _Bool   bool
+#define        __bool_locally_defined
+#endif
+
 /*
  * 7.17.5 Lock-free property.
  */
@@ -408,4 +413,9 @@ atomic_flag_clear(volatile atomic_flag *__object)
 }
 #endif /* !_KERNEL */
 
+#ifdef __bool_locally_defined
+#undef _Bool
+#undef __bool_locally_defined
+#endif
+
 #endif /* !_STDATOMIC_H_ */
This page took 0.029635 seconds and 5 git commands to generate.