Fix PR24114 - std::atomic for non-Clang is not a literal type
Add _LIBCPP_CONSTEXPR to the implementation of __gcc_atomic_t. git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@242172 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
119ed47999
commit
26edd804ba
@ -554,7 +554,8 @@ namespace __gcc_atomic {
|
|||||||
template <typename _Tp>
|
template <typename _Tp>
|
||||||
struct __gcc_atomic_t {
|
struct __gcc_atomic_t {
|
||||||
__gcc_atomic_t() _NOEXCEPT {}
|
__gcc_atomic_t() _NOEXCEPT {}
|
||||||
explicit __gcc_atomic_t(_Tp value) _NOEXCEPT : __a_value(value) {}
|
_LIBCPP_CONSTEXPR explicit __gcc_atomic_t(_Tp value) _NOEXCEPT
|
||||||
|
: __a_value(value) {}
|
||||||
_Tp __a_value;
|
_Tp __a_value;
|
||||||
};
|
};
|
||||||
#define _Atomic(x) __gcc_atomic::__gcc_atomic_t<x>
|
#define _Atomic(x) __gcc_atomic::__gcc_atomic_t<x>
|
||||||
|
@ -0,0 +1,56 @@
|
|||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
//
|
||||||
|
// The LLVM Compiler Infrastructure
|
||||||
|
//
|
||||||
|
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||||
|
// Source Licenses. See LICENSE.TXT for details.
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
//
|
||||||
|
// UNSUPPORTED: libcpp-has-no-threads
|
||||||
|
// UNSUPPORTED: c++98, c++03
|
||||||
|
|
||||||
|
// <atomic>
|
||||||
|
|
||||||
|
// constexpr atomic<T>::atomic(T value)
|
||||||
|
|
||||||
|
#include <atomic>
|
||||||
|
#include <type_traits>
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
|
struct UserType {
|
||||||
|
int i;
|
||||||
|
|
||||||
|
UserType() noexcept {}
|
||||||
|
constexpr explicit UserType(int d) noexcept : i(d) {}
|
||||||
|
|
||||||
|
friend bool operator==(const UserType& x, const UserType& y) {
|
||||||
|
return x.i == y.i;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class Tp>
|
||||||
|
void test() {
|
||||||
|
typedef std::atomic<Tp> Atomic;
|
||||||
|
static_assert(std::is_literal_type<Atomic>::value, "");
|
||||||
|
constexpr Tp t(42);
|
||||||
|
{
|
||||||
|
constexpr Atomic a(t);
|
||||||
|
assert(a == t);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
constexpr Atomic a{t};
|
||||||
|
assert(a == t);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
constexpr Atomic a = ATOMIC_VAR_INIT(t);
|
||||||
|
assert(a == t);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
test<int>();
|
||||||
|
test<UserType>();
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user