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#include "atomic_helpers.h" 26 27struct UserType { 28 int i; 29 30 UserType() noexcept {} 31 constexpr explicit UserType(int d) noexcept : i(d) {} 32 33 friend bool operator==(const UserType& x, const UserType& y) { 34 return x.i == y.i; 35 } 36}; 37 38template <class Tp> 39struct TestFunc { 40 void operator()() const { 41 typedef std::atomic<Tp> Atomic; 42 static_assert(std::is_literal_type<Atomic>::value, ""); 43 constexpr Tp t(42); 44 { 45 constexpr Atomic a(t); 46 assert(a == t); 47 } 48 { 49 constexpr Atomic a{t}; 50 assert(a == t); 51 } 52 { 53 constexpr Atomic a = ATOMIC_VAR_INIT(t); 54 assert(a == t); 55 } 56 } 57}; 58 59 60int main() 61{ 62 TestFunc<UserType>()(); 63 TestEachIntegralType<TestFunc>()(); 64} 65