blob: acf6d439de435f4e74f0bee94fa27229ff238e8c [file] [log] [blame]
Howard Hinnant91e2f262010-12-07 20:46:14 +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//===----------------------------------------------------------------------===//
Jonathan Roelofs8d86b2e2014-09-05 19:45:05 +00009//
10// UNSUPPORTED: libcpp-has-no-threads
Howard Hinnant91e2f262010-12-07 20:46:14 +000011
12// <atomic>
13
14// template <class Integral>
15// Integral
16// atomic_fetch_or(volatile atomic<Integral>* obj, Integral op);
17//
18// template <class Integral>
19// Integral
20// atomic_fetch_or(atomic<Integral>* obj, Integral op);
21
22#include <atomic>
Richard Smith9efdc0b2012-04-19 00:50:47 +000023#include <type_traits>
Howard Hinnant91e2f262010-12-07 20:46:14 +000024#include <cassert>
25
26template <class T>
Dan Albert1d4a1ed2016-05-25 22:36:09 -070027void
28test()
29{
Howard Hinnant91e2f262010-12-07 20:46:14 +000030 {
31 typedef std::atomic<T> A;
32 A t;
33 std::atomic_init(&t, T(1));
34 assert(std::atomic_fetch_or(&t, T(2)) == T(1));
35 assert(t == T(3));
36 }
37 {
38 typedef std::atomic<T> A;
39 volatile A t;
40 std::atomic_init(&t, T(3));
41 assert(std::atomic_fetch_or(&t, T(2)) == T(3));
42 assert(t == T(3));
43 }
Dan Albert1d4a1ed2016-05-25 22:36:09 -070044}
Howard Hinnant91e2f262010-12-07 20:46:14 +000045
46int main()
47{
Dan Albert1d4a1ed2016-05-25 22:36:09 -070048 test<char>();
49 test<signed char>();
50 test<unsigned char>();
51 test<short>();
52 test<unsigned short>();
53 test<int>();
54 test<unsigned int>();
55 test<long>();
56 test<unsigned long>();
57 test<long long>();
58 test<unsigned long long>();
59 test<wchar_t>();
60#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
61 test<char16_t>();
62 test<char32_t>();
63#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
Howard Hinnant91e2f262010-12-07 20:46:14 +000064}