From 26edd804bacc4a915a1a13d9c5c42c59b714baa8 Mon Sep 17 00:00:00 2001 From: Eric Fiselier Date: Tue, 14 Jul 2015 17:50:27 +0000 Subject: [PATCH] Fix PR24114 - std::atomic for non-Clang is not a literal type Add _LIBCPP_CONSTEXPR to the implementation of __gcc_atomic_t. git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@242172 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/atomic | 3 +- .../ctor.pass.cpp | 56 +++++++++++++++++++ 2 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 test/std/atomics/atomics.types.operations/atomics.types.operations.req/ctor.pass.cpp diff --git a/include/atomic b/include/atomic index 5bc71f00..97a998d3 100644 --- a/include/atomic +++ b/include/atomic @@ -554,7 +554,8 @@ namespace __gcc_atomic { template struct __gcc_atomic_t { __gcc_atomic_t() _NOEXCEPT {} - explicit __gcc_atomic_t(_Tp value) _NOEXCEPT : __a_value(value) {} + _LIBCPP_CONSTEXPR explicit __gcc_atomic_t(_Tp value) _NOEXCEPT + : __a_value(value) {} _Tp __a_value; }; #define _Atomic(x) __gcc_atomic::__gcc_atomic_t diff --git a/test/std/atomics/atomics.types.operations/atomics.types.operations.req/ctor.pass.cpp b/test/std/atomics/atomics.types.operations/atomics.types.operations.req/ctor.pass.cpp new file mode 100644 index 00000000..0eda2338 --- /dev/null +++ b/test/std/atomics/atomics.types.operations/atomics.types.operations.req/ctor.pass.cpp @@ -0,0 +1,56 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// UNSUPPORTED: libcpp-has-no-threads +// UNSUPPORTED: c++98, c++03 + +// + +// constexpr atomic::atomic(T value) + +#include +#include +#include + +struct UserType { + int i; + + UserType() noexcept {} + constexpr explicit UserType(int d) noexcept : i(d) {} + + friend bool operator==(const UserType& x, const UserType& y) { + return x.i == y.i; + } +}; + +template +void test() { + typedef std::atomic Atomic; + static_assert(std::is_literal_type::value, ""); + constexpr Tp t(42); + { + constexpr Atomic a(t); + assert(a == t); + } + { + constexpr Atomic a{t}; + assert(a == t); + } + { + constexpr Atomic a = ATOMIC_VAR_INIT(t); + assert(a == t); + } +} + + +int main() +{ + test(); + test(); +}