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// UNSUPPORTED: libcpp-has-no-threads
11
12// <atomic>
13
14// template <class Integral>
15//     Integral
16//     atomic_fetch_or_explicit(volatile atomic<Integral>* obj, Integral op);
17//
18// template <class Integral>
19//     Integral
20//     atomic_fetch_or_explicit(atomic<Integral>* obj, Integral op);
21
22#include <atomic>
23#include <type_traits>
24#include <cassert>
25
26template <class T>
27void
28test()
29{
30    {
31        typedef std::atomic<T> A;
32        A t;
33        std::atomic_init(&t, T(1));
34        assert(std::atomic_fetch_or_explicit(&t, T(2),
35               std::memory_order_seq_cst) == T(1));
36        assert(t == T(3));
37    }
38    {
39        typedef std::atomic<T> A;
40        volatile A t;
41        std::atomic_init(&t, T(3));
42        assert(std::atomic_fetch_or_explicit(&t, T(2),
43               std::memory_order_seq_cst) == T(3));
44        assert(t == T(3));
45    }
46}
47
48int main()
49{
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}
67