diff --git a/libcxx/include/__atomic/atomic.h b/libcxx/include/__atomic/atomic.h index c65f9afe4f390..eead49dde6192 100644 --- a/libcxx/include/__atomic/atomic.h +++ b/libcxx/include/__atomic/atomic.h @@ -23,6 +23,7 @@ #include <__type_traits/is_integral.h> #include <__type_traits/is_nothrow_constructible.h> #include <__type_traits/is_same.h> +#include <__type_traits/is_trivially_copyable.h> #include <__type_traits/remove_const.h> #include <__type_traits/remove_pointer.h> #include <__type_traits/remove_volatile.h> @@ -230,8 +231,14 @@ struct __atomic_waitable_traits<__atomic_base<_Tp, _IsIntegral> > { } }; +template +struct __check_atomic_mandates { + using type _LIBCPP_NODEBUG = _Tp; + static_assert(is_trivially_copyable<_Tp>::value, "std::atomic requires that 'T' be a trivially copyable type"); +}; + template -struct atomic : public __atomic_base<_Tp> { +struct atomic : public __atomic_base::type> { using __base _LIBCPP_NODEBUG = __atomic_base<_Tp>; #if _LIBCPP_STD_VER >= 20 diff --git a/libcxx/include/__atomic/support.h b/libcxx/include/__atomic/support.h index 4b555ab483ca0..99d0f6aa543ca 100644 --- a/libcxx/include/__atomic/support.h +++ b/libcxx/include/__atomic/support.h @@ -10,7 +10,6 @@ #define _LIBCPP___ATOMIC_SUPPORT_H #include <__config> -#include <__type_traits/is_trivially_copyable.h> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -113,8 +112,6 @@ _LIBCPP_BEGIN_NAMESPACE_STD template > struct __cxx_atomic_impl : public _Base { - static_assert(is_trivially_copyable<_Tp>::value, "std::atomic requires that 'T' be a trivially copyable type"); - _LIBCPP_HIDE_FROM_ABI __cxx_atomic_impl() _NOEXCEPT = default; _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR explicit __cxx_atomic_impl(_Tp __value) _NOEXCEPT : _Base(__value) {} }; diff --git a/libcxx/test/std/atomics/atomics.types.generic/trivially_copyable.verify.cpp b/libcxx/test/std/atomics/atomics.types.generic/trivially_copyable.verify.cpp index 0955707cdcf38..452e65d569230 100644 --- a/libcxx/test/std/atomics/atomics.types.generic/trivially_copyable.verify.cpp +++ b/libcxx/test/std/atomics/atomics.types.generic/trivially_copyable.verify.cpp @@ -6,26 +6,23 @@ // //===----------------------------------------------------------------------===// +// XFAIL: FROZEN-CXX03-HEADERS-FIXME + // // template // struct atomic; -// This test checks that we static_assert inside std::atomic when T -// is not trivially copyable, however Clang will sometimes emit additional -// errors while trying to instantiate the rest of std::atomic. -// We silence those to make the test more robust. -// ADDITIONAL_COMPILE_FLAGS: -Xclang -verify-ignore-unexpected=error - #include struct NotTriviallyCopyable { - explicit NotTriviallyCopyable(int i) : i_(i) { } - NotTriviallyCopyable(const NotTriviallyCopyable &rhs) : i_(rhs.i_) { } + explicit NotTriviallyCopyable(int i) : i_(i) {} + NotTriviallyCopyable(const NotTriviallyCopyable& rhs) : i_(rhs.i_) {} int i_; }; void f() { NotTriviallyCopyable x(42); - std::atomic a(x); // expected-error@*:* {{std::atomic requires that 'T' be a trivially copyable type}} + std::atomic a( + x); // expected-error@*:* {{std::atomic requires that 'T' be a trivially copyable type}} }