[libcxx-commits] [libcxx] [libc++] Fix diagnostic for <stdatomic.h> before C++23 (PR #83351)
via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Feb 28 14:29:42 PST 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libcxx
Author: Louis Dionne (ldionne)
<details>
<summary>Changes</summary>
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/83351.diff
1 Files Affected:
- (modified) libcxx/include/atomic (+4-4)
``````````diff
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>
``````````
</details>
https://github.com/llvm/llvm-project/pull/83351
More information about the libcxx-commits
mailing list