]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Fix _Atomic(T) macro in <stdatomic.h> [PR115807]
authorJonathan Wakely <jwakely@redhat.com>
Sun, 7 Jul 2024 11:22:42 +0000 (12:22 +0100)
committerJonathan Wakely <redi@gcc.gnu.org>
Mon, 8 Jul 2024 19:40:35 +0000 (20:40 +0100)
The definition of the _Atomic(T) macro needs to refer to ::std::atomic,
not some other std::atomic relative to the current namespace.

libstdc++-v3/ChangeLog:

PR libstdc++/115807
* include/c_compatibility/stdatomic.h (_Atomic): Ensure it
refers to std::atomic in the global namespace.
* testsuite/29_atomics/headers/stdatomic.h/115807.cc: New test.

libstdc++-v3/include/c_compatibility/stdatomic.h
libstdc++-v3/testsuite/29_atomics/headers/stdatomic.h/115807.cc [new file with mode: 0644]

index 5403b52a036d117cc61232a5106d24e7bbfa63fe..72b9446eb170abf15937f17255236fdeda007840 100644 (file)
@@ -35,7 +35,7 @@
 #ifdef __cpp_lib_stdatomic_h // C++ >= 23
 #include <atomic>
 
-#define _Atomic(_Tp) std::atomic<_Tp>
+#define _Atomic(_Tp) ::std::atomic<_Tp>
 
 using std::memory_order;
 using std::memory_order_relaxed;
diff --git a/libstdc++-v3/testsuite/29_atomics/headers/stdatomic.h/115807.cc b/libstdc++-v3/testsuite/29_atomics/headers/stdatomic.h/115807.cc
new file mode 100644 (file)
index 0000000..14f320f
--- /dev/null
@@ -0,0 +1,14 @@
+// { dg-do compile { target c++23 } }
+#include <stdatomic.h>
+namespace other {
+  namespace std {
+    int atomic = 0;
+  }
+  _Atomic(long) a{};
+}
+
+#include <type_traits>
+
+namespace non::std {
+  static_assert( ::std::is_same_v<_Atomic(int), ::std::atomic<int>> );
+}