[libcxx-commits] [libcxx] [libc++] Fix diagnostic for <stdatomic.h> before C++23 (PR #83351)
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Feb 29 07:11:26 PST 2024
https://github.com/ldionne updated https://github.com/llvm/llvm-project/pull/83351
>From b259285da55a62fdd56092eb5169d715b09fccae Mon Sep 17 00:00:00 2001
From: Louis Dionne <ldionne.2 at gmail.com>
Date: Wed, 28 Feb 2024 17:22:45 -0500
Subject: [PATCH 1/2] [libc++] Fix diagnostic for <stdatomic.h> before C++23
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.
---
libcxx/include/atomic | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/libcxx/include/atomic b/libcxx/include/atomic
index 2e8f5b521a55eb..ab6fc566aabc02 100644
--- a/libcxx/include/atomic
+++ b/libcxx/include/atomic
@@ -587,6 +587,10 @@ template <class T>
*/
+#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 <__assert> // all public C++ headers provide the assertion handler
#include <__atomic/aliases.h>
#include <__atomic/atomic.h>
@@ -613,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>
>From 7e7379993382256ad13406fd977c88345fbc6860 Mon Sep 17 00:00:00 2001
From: Louis Dionne <ldionne.2 at gmail.com>
Date: Thu, 29 Feb 2024 10:11:15 -0500
Subject: [PATCH 2/2] Include __config first
---
libcxx/include/atomic | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/libcxx/include/atomic b/libcxx/include/atomic
index ab6fc566aabc02..b5de2731b67131 100644
--- a/libcxx/include/atomic
+++ b/libcxx/include/atomic
@@ -587,6 +587,8 @@ 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
@@ -606,7 +608,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)
More information about the libcxx-commits
mailing list