blob: 9fe4ac816448ea98785ed5f2c3e053f8b4412672 [file] [log] [blame]
Howard Hinnant4777bf22010-12-06 23:10:08 +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
11// ... assertion fails line 32
Howard Hinnant4777bf22010-12-06 23:10:08 +000012
13// <atomic>
14
15// template <class T>
16// T
17// atomic_exchange_explicit(volatile atomic<T>* obj, T desr, memory_order m);
18//
19// template <class T>
20// T
21// atomic_exchange_explicit(atomic<T>* obj, T desr, memory_order m);
22
23#include <atomic>
Richard Smith9efdc0b2012-04-19 00:50:47 +000024#include <type_traits>
Howard Hinnant4777bf22010-12-06 23:10:08 +000025#include <cassert>
26
27template <class T>
Dan Albert1d4a1ed2016-05-25 22:36:09 -070028void
29test()
30{
Howard Hinnant4777bf22010-12-06 23:10:08 +000031 typedef std::atomic<T> A;
32 A t;
33 std::atomic_init(&t, T(1));
34 assert(std::atomic_exchange_explicit(&t, T(2), std::memory_order_seq_cst)
35 == T(1));
36 assert(t == T(2));
37 volatile A vt;
38 std::atomic_init(&vt, T(3));
39 assert(std::atomic_exchange_explicit(&vt, T(4), std::memory_order_seq_cst)
40 == T(3));
41 assert(vt == T(4));
Dan Albert1d4a1ed2016-05-25 22:36:09 -070042}
Howard Hinnant4777bf22010-12-06 23:10:08 +000043
Dan Albert1d4a1ed2016-05-25 22:36:09 -070044struct A
45{
46 int i;
47
48 explicit A(int d = 0) noexcept {i=d;}
49
50 friend bool operator==(const A& x, const A& y)
51 {return x.i == y.i;}
52};
Eric Fiselier00f4a492015-08-19 17:21:46 +000053
Howard Hinnant4777bf22010-12-06 23:10:08 +000054int main()
55{
Dan Albert1d4a1ed2016-05-25 22:36:09 -070056 test<A>();
57 test<char>();
58 test<signed char>();
59 test<unsigned char>();
60 test<short>();
61 test<unsigned short>();
62 test<int>();
63 test<unsigned int>();
64 test<long>();
65 test<unsigned long>();
66 test<long long>();
67 test<unsigned long long>();
68 test<wchar_t>();
69#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
70 test<char16_t>();
71 test<char32_t>();
72#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
73 test<int*>();
74 test<const int*>();
Howard Hinnant4777bf22010-12-06 23:10:08 +000075}