blob: f85172a0149cc892d9a21b6ade1af148411b15a8 [file] [log] [blame]
Eric Fiselier26edd802015-07-14 17:50:27 +00001//===----------------------------------------------------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// UNSUPPORTED: libcpp-has-no-threads
11// UNSUPPORTED: c++98, c++03
12
Justin Bogner3a59ae62015-07-22 23:32:57 +000013// NOTE: atomic<> of a TriviallyCopyable class is wrongly rejected by older
14// clang versions. It was fixed right before the llvm 3.5 release. See PR18097.
15// XFAIL: apple-clang-6.0, clang-3.4, clang-3.3
16
Eric Fiselier26edd802015-07-14 17:50:27 +000017// <atomic>
18
19// constexpr atomic<T>::atomic(T value)
20
21#include <atomic>
22#include <type_traits>
23#include <cassert>
24
25struct UserType {
26 int i;
27
28 UserType() noexcept {}
29 constexpr explicit UserType(int d) noexcept : i(d) {}
30
31 friend bool operator==(const UserType& x, const UserType& y) {
32 return x.i == y.i;
33 }
34};
35
36template <class Tp>
Dan Albert1d4a1ed2016-05-25 22:36:09 -070037void test() {
38 typedef std::atomic<Tp> Atomic;
39 static_assert(std::is_literal_type<Atomic>::value, "");
40 constexpr Tp t(42);
41 {
42 constexpr Atomic a(t);
43 assert(a == t);
Eric Fiselier26edd802015-07-14 17:50:27 +000044 }
Dan Albert1d4a1ed2016-05-25 22:36:09 -070045 {
46 constexpr Atomic a{t};
47 assert(a == t);
48 }
49 {
50 constexpr Atomic a = ATOMIC_VAR_INIT(t);
51 assert(a == t);
52 }
53}
Eric Fiselier26edd802015-07-14 17:50:27 +000054
55
56int main()
57{
Dan Albert1d4a1ed2016-05-25 22:36:09 -070058 test<int>();
59 test<UserType>();
Eric Fiselier26edd802015-07-14 17:50:27 +000060}