[libcxx-commits] [libcxx] 40081a4 - [libc++] Fix diagnostic for <stdatomic.h> before C++23 (#83351)
via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Mar 4 15:24:56 PST 2024
Author: Louis Dionne
Date: 2024-03-04T18:24:51-05:00
New Revision: 40081a45a14f7aa6249fa034d961549c0b1762a0
URL: https://github.com/llvm/llvm-project/commit/40081a45a14f7aa6249fa034d961549c0b1762a0
DIFF: https://github.com/llvm/llvm-project/commit/40081a45a14f7aa6249fa034d961549c0b1762a0.diff
LOG: [libc++] Fix diagnostic for <stdatomic.h> before C++23 (#83351)
We normally try to issue a reasonable diagnostic when mixing
<stdatomic.h> and <atomic> before C++23. However, after granularizing
the <atomic> header, the check and the #error message was moved to
*after* the point where mixing both causes problems. When mixing both
headers, we would hence get the diagnostic burried under a pile of
previous diagnostics in e.g. __atomic/kill_dependency.h.
This patch moves the check earlier to restore the intended behavior. It
also switches from `#ifdef kill_dependency` to an explicit check of the
inclusion of the header and the Standard version, which seems to be more
reliable than checking whether a macro is defined.
Added:
Modified:
libcxx/include/atomic
Removed:
################################################################################
diff --git a/libcxx/include/atomic b/libcxx/include/atomic
index 61ff61d415dd84..cb142b09bff333 100644
--- a/libcxx/include/atomic
+++ b/libcxx/include/atomic
@@ -587,6 +587,12 @@ template <class T>
*/
+#include <__config>
+
+#if _LIBCPP_STD_VER < 23 && defined(_LIBCPP_STDATOMIC_H)
+# error <atomic> is incompatible with <stdatomic.h> before C++23. Please compile with -std=c++23.
+#endif
+
#include <__atomic/aliases.h>
#include <__atomic/atomic.h>
#include <__atomic/atomic_base.h>
@@ -601,7 +607,6 @@ template <class T>
#include <__atomic/is_always_lock_free.h>
#include <__atomic/kill_dependency.h>
#include <__atomic/memory_order.h>
-#include <__config>
#include <version>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
@@ -612,10 +617,6 @@ template <class T>
# error <atomic> is not implemented
#endif
-#ifdef kill_dependency
-# error <atomic> is incompatible with <stdatomic.h> before C++23. Please compile with -std=c++23.
-#endif
-
#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
# include <cmath>
# include <compare>
More information about the libcxx-commits
mailing list