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 // 12 // This test uses new symbols that were not defined in the libc++ shipped on 13 // darwin11 and darwin12: 14 // XFAIL: availability=macosx10.7 15 // XFAIL: availability=macosx10.8 16 17 // <memory> 18 19 // shared_ptr 20 21 // template <class T> 22 // bool 23 // atomic_compare_exchange_weak(shared_ptr<T>* p, shared_ptr<T>* v, 24 // shared_ptr<T> w); 25 26 // UNSUPPORTED: c++98, c++03 27 28 #include <memory> 29 #include <cassert> 30 31 #include "test_macros.h" 32 33 int main() 34 { 35 { 36 std::shared_ptr<int> p(new int(4)); 37 std::shared_ptr<int> v(new int(3)); 38 std::shared_ptr<int> w(new int(2)); 39 bool b = std::atomic_compare_exchange_weak(&p, &v, w); 40 assert(b == false); 41 assert(*p == 4); 42 assert(*v == 4); 43 assert(*w == 2); 44 } 45 { 46 std::shared_ptr<int> p(new int(4)); 47 std::shared_ptr<int> v = p; 48 std::shared_ptr<int> w(new int(2)); 49 bool b = std::atomic_compare_exchange_weak(&p, &v, w); 50 assert(b == true); 51 assert(*p == 2); 52 assert(*v == 4); 53 assert(*w == 2); 54 } 55 } 56