[committed] libstdc++: Fix _Atomic(T) macro in <stdatomic.h> [PR115807]

Message ID 20240708194124.491509-1-jwakely@redhat.com
State New
Headers
Series [committed] libstdc++: Fix _Atomic(T) macro in <stdatomic.h> [PR115807] |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gcc_build--master-arm warning Patch is already merged
linaro-tcwg-bot/tcwg_gcc_build--master-aarch64 warning Patch is already merged

Commit Message

Jonathan Wakely July 8, 2024, 7:41 p.m. UTC
  Tested x86_64-linux. Pushed to trunk. This should be backported too.

-- >8 --

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   |  2 +-
 .../29_atomics/headers/stdatomic.h/115807.cc       | 14 ++++++++++++++
 2 files changed, 15 insertions(+), 1 deletion(-)
 create mode 100644 libstdc++-v3/testsuite/29_atomics/headers/stdatomic.h/115807.cc
  

Patch

diff --git a/libstdc++-v3/include/c_compatibility/stdatomic.h b/libstdc++-v3/include/c_compatibility/stdatomic.h
index 5403b52a036..72b9446eb17 100644
--- a/libstdc++-v3/include/c_compatibility/stdatomic.h
+++ b/libstdc++-v3/include/c_compatibility/stdatomic.h
@@ -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
index 00000000000..14f320fe835
--- /dev/null
+++ b/libstdc++-v3/testsuite/29_atomics/headers/stdatomic.h/115807.cc
@@ -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>> );
+}