blob: 137b6f60f74608357e1ac1512c4293a72ac9498c [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
Dan Albert1d4a1ed2016-05-25 22:36:09 -070011// ... assertion fails line 34
Howard Hinnant4777bf22010-12-06 23:10:08 +000012
13// <atomic>
14
15// template <class T>
16// void
17// atomic_init(volatile atomic<T>* obj, T desr);
18//
19// template <class T>
20// void
21// atomic_init(atomic<T>* obj, T desr);
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(t == T(1));
35 volatile A vt;
36 std::atomic_init(&vt, T(2));
37 assert(vt == T(2));
Dan Albert1d4a1ed2016-05-25 22:36:09 -070038}
39
40struct A
41{
42 int i;
43
44 explicit A(int d = 0) noexcept {i=d;}
45
46 friend bool operator==(const A& x, const A& y)
47 {return x.i == y.i;}
Howard Hinnant4777bf22010-12-06 23:10:08 +000048};
49
50int main()
51{
Dan Albert1d4a1ed2016-05-25 22:36:09 -070052 test<A>();
53 test<char>();
54 test<signed char>();
55 test<unsigned char>();
56 test<short>();
57 test<unsigned short>();
58 test<int>();
59 test<unsigned int>();
60 test<long>();
61 test<unsigned long>();
62 test<long long>();
63 test<unsigned long long>();
64 test<wchar_t>();
65#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
66 test<char16_t>();
67 test<char32_t>();
68#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
69 test<int*>();
70 test<const int*>();
Howard Hinnant4777bf22010-12-06 23:10:08 +000071}