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