Home | History | Annotate | Download | only in atomics.types.operations.req
      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 // UNSUPPORTED: c++98, c++03
     12 
     13 // NOTE: atomic<> of a TriviallyCopyable class is wrongly rejected by older
     14 // clang versions. It was fixed right before the llvm 3.5 release. See PR18097.
     15 // XFAIL: apple-clang-6.0, clang-3.4, clang-3.3
     16 
     17 // <atomic>
     18 
     19 // constexpr atomic<T>::atomic(T value)
     20 
     21 #include <atomic>
     22 #include <type_traits>
     23 #include <cassert>
     24 
     25 struct UserType {
     26     int i;
     27 
     28     UserType() noexcept {}
     29     constexpr explicit UserType(int d) noexcept : i(d) {}
     30 
     31     friend bool operator==(const UserType& x, const UserType& y) {
     32         return x.i == y.i;
     33     }
     34 };
     35 
     36 template <class Tp>
     37 void test() {
     38     typedef std::atomic<Tp> Atomic;
     39     static_assert(std::is_literal_type<Atomic>::value, "");
     40     constexpr Tp t(42);
     41     {
     42         constexpr Atomic a(t);
     43         assert(a == t);
     44     }
     45     {
     46         constexpr Atomic a{t};
     47         assert(a == t);
     48     }
     49     {
     50         constexpr Atomic a = ATOMIC_VAR_INIT(t);
     51         assert(a == t);
     52     }
     53 }
     54 
     55 
     56 int main()
     57 {
     58     test<int>();
     59     test<UserType>();
     60 }
     61