cpp_atomic_ops_linkable.cc revision 1.1 1 /* $NetBSD: cpp_atomic_ops_linkable.cc,v 1.1 2014/10/11 14:52:15 martin Exp $ */
2
3 /*-
4 * Copyright (c) 2014 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Martin Husemann <martin (at) NetBSD.org>.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 /*
33 * This is a simple link-time test to verify all builtin atomic sync
34 * operations for C++ <atomic> are available.
35 */
36
37 #include <atomic>
38
39 template <class T>
40 class ATest {
41 public:
42 ATest() : m_val(0)
43 {
44 m_val.exchange(std::atomic<T>(8));
45 m_val--;
46 m_val++;
47 m_val ^= 0x0f;
48 m_val &= 0x0f;
49 m_val |= 2;
50
51 T tval(1), other(42);
52 m_val.compare_exchange_weak(tval, other,
53 std::memory_order_release, std::memory_order_relaxed);
54 }
55
56 private:
57 volatile std::atomic<T> m_val;
58 };
59
60 int main(int argc, char **argv)
61 {
62 ATest<char>();
63 ATest<signed char>();
64 ATest<unsigned char>();
65 ATest<short>();
66 ATest<unsigned short>();
67 ATest<int>();
68 ATest<unsigned int>();
69 ATest<long>();
70 ATest<unsigned long>();
71 ATest<long long>();
72 ATest<unsigned long long>();
73 ATest<char16_t>();
74 ATest<char32_t>();
75 ATest<wchar_t>();
76 ATest<int_least8_t>();
77 ATest<uint_least8_t>();
78 ATest<int_least16_t>();
79 ATest<uint_least16_t>();
80 ATest<int_least32_t>();
81 ATest<uint_least32_t>();
82 ATest<int_least64_t>();
83 ATest<uint_least64_t>();
84 ATest<int_fast8_t>();
85 ATest<uint_fast8_t>();
86 ATest<int_fast16_t>();
87 ATest<uint_fast16_t>();
88 ATest<int_fast32_t>();
89 ATest<uint_fast32_t>();
90 ATest<int_fast64_t>();
91 ATest<uint_fast64_t>();
92 ATest<intptr_t>();
93 ATest<uintptr_t>();
94 ATest<std::size_t>();
95 ATest<std::ptrdiff_t>();
96 ATest<intmax_t>();
97 ATest<uintmax_t>();
98 }
99