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