Eric Fiselier | 26edd80 | 2015-07-14 17:50:27 +0000 | [diff] [blame] | 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 | |
Justin Bogner | 3a59ae6 | 2015-07-22 23:32:57 +0000 | [diff] [blame] | 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 | |
Eric Fiselier | 26edd80 | 2015-07-14 17:50:27 +0000 | [diff] [blame] | 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> |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 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); |
Eric Fiselier | 26edd80 | 2015-07-14 17:50:27 +0000 | [diff] [blame] | 44 | } |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 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 | } |
Eric Fiselier | 26edd80 | 2015-07-14 17:50:27 +0000 | [diff] [blame] | 54 | |
| 55 | |
| 56 | int main() |
| 57 | { |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 58 | test<int>(); |
| 59 | test<UserType>(); |
Eric Fiselier | 26edd80 | 2015-07-14 17:50:27 +0000 | [diff] [blame] | 60 | } |