Skip to content

Commit 40081a4

Browse files
authored
[libc++] Fix diagnostic for <stdatomic.h> before C++23 (llvm#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.
1 parent 5174b38 commit 40081a4

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

libcxx/include/atomic

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,12 @@ template <class T>
587587
588588
*/
589589

590+
#include <__config>
591+
592+
#if _LIBCPP_STD_VER < 23 && defined(_LIBCPP_STDATOMIC_H)
593+
# error <atomic> is incompatible with <stdatomic.h> before C++23. Please compile with -std=c++23.
594+
#endif
595+
590596
#include <__atomic/aliases.h>
591597
#include <__atomic/atomic.h>
592598
#include <__atomic/atomic_base.h>
@@ -601,7 +607,6 @@ template <class T>
601607
#include <__atomic/is_always_lock_free.h>
602608
#include <__atomic/kill_dependency.h>
603609
#include <__atomic/memory_order.h>
604-
#include <__config>
605610
#include <version>
606611

607612
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
@@ -612,10 +617,6 @@ template <class T>
612617
# error <atomic> is not implemented
613618
#endif
614619

615-
#ifdef kill_dependency
616-
# error <atomic> is incompatible with <stdatomic.h> before C++23. Please compile with -std=c++23.
617-
#endif
618-
619620
#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
620621
# include <cmath>
621622
# include <compare>

0 commit comments

Comments
 (0)