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// <atomic> 11 12// template <class Integral> 13// Integral 14// atomic_fetch_and(volatile atomic<Integral>* obj, Integral op); 15// 16// template <class Integral> 17// Integral 18// atomic_fetch_and(atomic<Integral>* obj, Integral op); 19 20#include <atomic> 21#include <type_traits> 22#include <cassert> 23 24template <class T> 25void 26test() 27{ 28 { 29 typedef std::atomic<T> A; 30 A t; 31 std::atomic_init(&t, T(1)); 32 assert(std::atomic_fetch_and(&t, T(2)) == T(1)); 33 assert(t == T(0)); 34 } 35 { 36 typedef std::atomic<T> A; 37 volatile A t; 38 std::atomic_init(&t, T(3)); 39 assert(std::atomic_fetch_and(&t, T(2)) == T(3)); 40 assert(t == T(2)); 41 } 42} 43 44int main() 45{ 46 test<char>(); 47 test<signed char>(); 48 test<unsigned char>(); 49 test<short>(); 50 test<unsigned short>(); 51 test<int>(); 52 test<unsigned int>(); 53 test<long>(); 54 test<unsigned long>(); 55 test<long long>(); 56 test<unsigned long long>(); 57 test<wchar_t>(); 58#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS 59 test<char16_t>(); 60 test<char32_t>(); 61#endif // _LIBCPP_HAS_NO_UNICODE_CHARS 62} 63