//===----------------------------------------------------------------------===//
//
//                     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>();
}

//===----------------------------------------------------------------------===//
//
//                     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

// NOTE: atomic<> of a TriviallyCopyable class is wrongly rejected by older
// clang versions. It was fixed right before the llvm 3.5 release. See PR18097.
// XFAIL: apple-clang-6.0, clang-3.4, clang-3.3

// <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>();
}

Mark this test as XFAIL with older compilers, since they hit PR18097
Mark this test as XFAIL with older compilers, since they hit PR18097

git-svn-id: 756ef344af921d95d562d9e9f9389127a89a6314@242967 91177308-0d34-0410-b5e6-96231b3b80d8
