diff --git a/libcxx/include/stdatomic.h b/libcxx/include/stdatomic.h index 2991030eee456..f27c8936ce790 100644 --- a/libcxx/include/stdatomic.h +++ b/libcxx/include/stdatomic.h @@ -135,7 +135,12 @@ using std::atomic_signal_fence // see below # undef _Atomic # endif -# define _Atomic(_Tp) ::std::atomic<_Tp> +_LIBCPP_BEGIN_NAMESPACE_STD +template +using __libcpp_atomic_alias _LIBCPP_NODEBUG = atomic<_Tp>; +_LIBCPP_END_NAMESPACE_STD + +# define _Atomic(_Tp) ::std::__libcpp_atomic_alias<_Tp> using std::memory_order _LIBCPP_USING_IF_EXISTS; using std::memory_order_relaxed _LIBCPP_USING_IF_EXISTS; diff --git a/libcxx/test/std/atomics/stdatomic.h.syn/alias.template.verify.cpp b/libcxx/test/std/atomics/stdatomic.h.syn/alias.template.verify.cpp new file mode 100644 index 0000000000000..69b35ade1fd46 --- /dev/null +++ b/libcxx/test/std/atomics/stdatomic.h.syn/alias.template.verify.cpp @@ -0,0 +1,25 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// REQUIRES: std-at-least-c++23 +// UNSUPPORTED: no-threads + +// + +// template +// using std-atomic = std::atomic; // exposition only +// +// #define _Atomic(T) std-atomic + +// Verify that _Atomic(T) directly uses an alias template but not the std::atomic class template. +// See also https://llvm.org/PR168579. + +#include + +struct _Atomic(int) x; +// expected-error-re@-1{{alias template '{{.*}}' cannot be referenced with the 'struct' specifier}}