1//===----------------------------------------------------------------------===//
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// <atomic>
11
12// template <class T>
13//     T
14//     atomic_load(const volatile atomic<T>* obj);
15//
16// template <class T>
17//     T
18//     atomic_load(const atomic<T>* obj);
19
20#include <atomic>
21#include <type_traits>
22#include <cassert>
23
24template <class T>
25void
26test()
27{
28    typedef std::atomic<T> A;
29    A t;
30    std::atomic_init(&t, T(1));
31    assert(std::atomic_load(&t) == T(1));
32    volatile A vt;
33    std::atomic_init(&vt, T(2));
34    assert(std::atomic_load(&vt) == T(2));
35}
36
37struct A
38{
39    int i;
40
41    explicit A(int d = 0) : i(d) {}
42
43    friend bool operator==(const A& x, const A& y)
44        {return x.i == y.i;}
45};
46
47int main()
48{
49    test<A>();
50    test<char>();
51    test<signed char>();
52    test<unsigned char>();
53    test<short>();
54    test<unsigned short>();
55    test<int>();
56    test<unsigned int>();
57    test<long>();
58    test<unsigned long>();
59    test<long long>();
60    test<unsigned long long>();
61    test<wchar_t>();
62#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
63    test<char16_t>();
64    test<char32_t>();
65#endif  // _LIBCPP_HAS_NO_UNICODE_CHARS
66    test<int*>();
67    test<const int*>();
68}
69