summaryrefslogtreecommitdiff
path: root/libcxx/include/stdatomic.h
diff options
context:
space:
mode:
authorGergely Nagy <ngg@ngg.hu>2022-09-27 07:59:55 -0400
committerLouis Dionne <ldionne.2@gmail.com>2022-09-27 13:13:11 -0400
commitafec0f0ec38a72bcc6a697c1cefb1dac0bbd02fb (patch)
treec2329a868edd5c2ab5091b337b7fc25c4505c2c3 /libcxx/include/stdatomic.h
parent4c6683cd68219d02fcd4c295924995db6b77516d (diff)
[libcxx] Make stdatomic.h work when included from a C source file
If a C source file includes the libc++ stdatomic.h, compilation will break because (a) the C++ standard check will fail (which is expected), and (b) `_LIBCPP_COMPILER_CLANG_BASED` won't be defined because the logic defining it in `__config` is guarded by a `__cplusplus` check, so we'll end up with a blank header. Move the detection logic outside of the `__cplusplus` check to make the second check pass even in a C context when you're using Clang. Note that `_LIBCPP_STD_VER` is not defined when in C mode, hence stdatomic.h needs to check if in C++ mode before using that macro to avoid a warning. In an ideal world, a C source file wouldn't be including the libc++ header directory in its search path, so we'd never have this issue. Unfortunately, certain build environments make this hard to guarantee, and in this case it's easy to tweak this header to make it work in a C context, so I'm hoping this is acceptable. Fixes https://github.com/llvm/llvm-project/issues/57710. Differential Revision: https://reviews.llvm.org/D134591
Diffstat (limited to 'libcxx/include/stdatomic.h')
-rw-r--r--libcxx/include/stdatomic.h4
1 files changed, 2 insertions, 2 deletions
diff --git a/libcxx/include/stdatomic.h b/libcxx/include/stdatomic.h
index d9550c44061c..ff2a5682f5bb 100644
--- a/libcxx/include/stdatomic.h
+++ b/libcxx/include/stdatomic.h
@@ -121,7 +121,7 @@ using std::atomic_signal_fence // see below
# pragma GCC system_header
#endif
-#if _LIBCPP_STD_VER > 20
+#if defined(__cplusplus) && _LIBCPP_STD_VER > 20
#include <atomic>
#include <version>
@@ -230,6 +230,6 @@ using std::atomic_thread_fence _LIBCPP_USING_IF_EXISTS;
# include_next <stdatomic.h>
# endif
-#endif // _LIBCPP_STD_VER > 20
+#endif // defined(__cplusplus) && _LIBCPP_STD_VER > 20
#endif // _LIBCPP_STDATOMIC_H