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// ... assertion fails line 34 12 13// <atomic> 14 15// template <class T> 16// bool 17// atomic_compare_exchange_strong(volatile atomic<T>* obj, T* expc, T desr); 18// 19// template <class T> 20// bool 21// atomic_compare_exchange_strong(atomic<T>* obj, T* expc, T desr); 22 23#include <atomic> 24#include <type_traits> 25#include <cassert> 26 27template <class T> 28void 29test() 30{ 31 { 32 typedef std::atomic<T> A; 33 A a; 34 T t(T(1)); 35 std::atomic_init(&a, t); 36 assert(std::atomic_compare_exchange_strong(&a, &t, T(2)) == true); 37 assert(a == T(2)); 38 assert(t == T(1)); 39 assert(std::atomic_compare_exchange_strong(&a, &t, T(3)) == false); 40 assert(a == T(2)); 41 assert(t == T(2)); 42 } 43 { 44 typedef std::atomic<T> A; 45 volatile A a; 46 T t(T(1)); 47 std::atomic_init(&a, t); 48 assert(std::atomic_compare_exchange_strong(&a, &t, T(2)) == true); 49 assert(a == T(2)); 50 assert(t == T(1)); 51 assert(std::atomic_compare_exchange_strong(&a, &t, T(3)) == false); 52 assert(a == T(2)); 53 assert(t == T(2)); 54 } 55} 56 57struct A 58{ 59 int i; 60 61 explicit A(int d = 0) noexcept {i=d;} 62 63 friend bool operator==(const A& x, const A& y) 64 {return x.i == y.i;} 65}; 66 67int main() 68{ 69 test<A>(); 70 test<char>(); 71 test<signed char>(); 72 test<unsigned char>(); 73 test<short>(); 74 test<unsigned short>(); 75 test<int>(); 76 test<unsigned int>(); 77 test<long>(); 78 test<unsigned long>(); 79 test<long long>(); 80 test<unsigned long long>(); 81 test<wchar_t>(); 82#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS 83 test<char16_t>(); 84 test<char32_t>(); 85#endif // _LIBCPP_HAS_NO_UNICODE_CHARS 86 test<int*>(); 87 test<const int*>(); 88} 89