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

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.

(cherry picked from commit 40d234dd64)
This commit is contained in:
Jonathan Wakely 2024-07-07 12:22:42 +01:00
parent 3cd410fe4f
commit c36ef56fc1
2 changed files with 15 additions and 1 deletions

View File

@ -34,7 +34,7 @@
#define __cpp_lib_stdatomic_h 202011L #define __cpp_lib_stdatomic_h 202011L
#define _Atomic(_Tp) std::atomic<_Tp> #define _Atomic(_Tp) ::std::atomic<_Tp>
using std::memory_order; using std::memory_order;
using std::memory_order_relaxed; using std::memory_order_relaxed;

View File

@ -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>> );
}