[libcxx-commits] [PATCH] D75183: [libcxx] Guard C++20 atomic type aliases

Mikhail Maltsev via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Wed Feb 26 08:05:01 PST 2020


miyuki created this revision.
miyuki added reviewers: ldionne, __simt__.
Herald added a reviewer: EricWF.
Herald added subscribers: libcxx-commits, jfb, dexonsmith, kristof.beyls.
Herald added a reviewer: jfb.
Herald added a project: libc++.

The std::atomic_signed_lock_free and std::atomic_unsigned_lock_free
typedefs are a C++20 feature and should be guarded with an #if, so
that they don't get defined in C++17 and prior versions.

Also with the current implementation inclusion of the <atomic> header
will fail the compilation for targets that don't have lock-free atomic
integers (e.g. Armv6-M) because __libcpp_signed_lock_free and
__libcpp_unsigned_lock_free will not get defined. We should not try to
define std::atomic_signed_lock_free and std::atomic_unsigned_lock_free
in this case as well (according to [atomics.alias]/2 these typedefs
are optional in freestanding implementations).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D75183

Files:
  libcxx/include/atomic


Index: libcxx/include/atomic
===================================================================
--- libcxx/include/atomic
+++ libcxx/include/atomic
@@ -2737,6 +2737,8 @@
 # define _LIBCPP_CONTENTION_LOCK_FREE false
 #endif
 
+#if _LIBCPP_STD_VER > 17
+
 #if ATOMIC_LLONG_LOCK_FREE == 2
 typedef conditional<_LIBCPP_CONTENTION_LOCK_FREE, __cxx_contention_t, long long>::type          __libcpp_signed_lock_free;
 typedef conditional<_LIBCPP_CONTENTION_LOCK_FREE, __cxx_contention_t, unsigned long long>::type __libcpp_unsigned_lock_free;
@@ -2751,10 +2753,15 @@
 typedef conditional<_LIBCPP_CONTENTION_LOCK_FREE, __cxx_contention_t, unsigned char>::type      __libcpp_unsigned_lock_free;
 #else
     // No signed/unsigned lock-free types
+# define _LIBCPP_CANNOT_DEFINE_ATOMIC_LOCK_FREE_TYPE_ALIASES
 #endif
 
+#ifndef _LIBCPP_CANNOT_DEFINE_ATOMIC_LOCK_FREE_TYPE_ALIASES
 typedef atomic<__libcpp_signed_lock_free> atomic_signed_lock_free;
 typedef atomic<__libcpp_unsigned_lock_free> atomic_unsigned_lock_free;
+#endif
+
+#endif // _LIBCPP_STD_VER > 17
 
 #define ATOMIC_FLAG_INIT {false}
 #define ATOMIC_VAR_INIT(__v) {__v}


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D75183.246736.patch
Type: text/x-patch
Size: 1124 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20200226/0412d75c/attachment-0001.bin>


More information about the libcxx-commits mailing list