diff options
| author | Howard Hinnant <hhinnant@apple.com> | 2013-05-02 20:18:43 +0000 |
|---|---|---|
| committer | Howard Hinnant <hhinnant@apple.com> | 2013-05-02 20:18:43 +0000 |
| commit | da9ca0b40545067f24a1088cb391b55d29858fc2 (patch) | |
| tree | fdb2083c0c4a0c26b169421838051416bbd029b6 /libcxx/test | |
| parent | c76d7e3d96dc053865a7f334c41727346d67ec78 (diff) | |
| download | bcm5719-llvm-da9ca0b40545067f24a1088cb391b55d29858fc2.tar.gz bcm5719-llvm-da9ca0b40545067f24a1088cb391b55d29858fc2.zip | |
Stephan Tolksdorf: fixes the issue in the <atomic> header and adds corresponding tests. I've used macros to fall back to a user-provided default constructor if _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS (though I suspect that there won't be many users defining that macro).
The tests use placement new to check that atomic values get properly zero-initialized. I had to modify the atomic_is_lock_free test, because default initialization of an object of const type 'const A' (aka 'const atomic<int>') requires a user-provided default constructor.
llvm-svn: 180945
Diffstat (limited to 'libcxx/test')
5 files changed, 37 insertions, 4 deletions
diff --git a/libcxx/test/atomics/atomics.flag/default.pass.cpp b/libcxx/test/atomics/atomics.flag/default.pass.cpp index 489e3d2b8f8..5c077b0a166 100644 --- a/libcxx/test/atomics/atomics.flag/default.pass.cpp +++ b/libcxx/test/atomics/atomics.flag/default.pass.cpp @@ -14,9 +14,18 @@ // atomic_flag() = default; #include <atomic> +#include <new> #include <cassert> int main() { std::atomic_flag f; + + { + typedef std::atomic_flag A; + _ALIGNAS_TYPE(A) char storage[sizeof(A)] = {1}; + A& zero = *new (storage) A(); + assert(!zero.test_and_set()); + zero.~A(); + } } diff --git a/libcxx/test/atomics/atomics.types.generic/address.pass.cpp b/libcxx/test/atomics/atomics.types.generic/address.pass.cpp index 1cfdef501ae..af9826f7f40 100644 --- a/libcxx/test/atomics/atomics.types.generic/address.pass.cpp +++ b/libcxx/test/atomics/atomics.types.generic/address.pass.cpp @@ -66,6 +66,7 @@ // }; #include <atomic> +#include <new> #include <type_traits> #include <cassert> @@ -112,6 +113,13 @@ do_test() assert(obj == T(5*sizeof(X))); assert((obj -= std::ptrdiff_t(3)) == T(2*sizeof(X))); assert(obj == T(2*sizeof(X))); + + { + _ALIGNAS_TYPE(A) char storage[sizeof(A)] = {23}; + A& zero = *new (storage) A(); + assert(zero == 0); + zero.~A(); + } } template <class A, class T> diff --git a/libcxx/test/atomics/atomics.types.generic/bool.pass.cpp b/libcxx/test/atomics/atomics.types.generic/bool.pass.cpp index f6379dc7af9..80e5665638c 100644 --- a/libcxx/test/atomics/atomics.types.generic/bool.pass.cpp +++ b/libcxx/test/atomics/atomics.types.generic/bool.pass.cpp @@ -50,6 +50,7 @@ // typedef atomic<bool> atomic_bool; #include <atomic> +#include <new> #include <cassert> int main() @@ -219,4 +220,11 @@ int main() assert((obj = true) == true); assert(obj == true); } + { + typedef std::atomic<bool> A; + _ALIGNAS_TYPE(A) char storage[sizeof(A)] = {1}; + A& zero = *new (storage) A(); + assert(zero == false); + zero.~A(); + } } diff --git a/libcxx/test/atomics/atomics.types.generic/integral.pass.cpp b/libcxx/test/atomics/atomics.types.generic/integral.pass.cpp index fc678bcfae4..26caa5001d5 100644 --- a/libcxx/test/atomics/atomics.types.generic/integral.pass.cpp +++ b/libcxx/test/atomics/atomics.types.generic/integral.pass.cpp @@ -85,6 +85,7 @@ // }; #include <atomic> +#include <new> #include <cassert> template <class A, class T> @@ -143,6 +144,13 @@ do_test() assert(obj == T(7)); assert((obj ^= T(0xF)) == T(8)); assert(obj == T(8)); + + { + _ALIGNAS_TYPE(A) char storage[sizeof(A)] = {23}; + A& zero = *new (storage) A(); + assert(zero == 0); + zero.~A(); + } } template <class A, class T> diff --git a/libcxx/test/atomics/atomics.types.operations/atomics.types.operations.req/atomic_is_lock_free.pass.cpp b/libcxx/test/atomics/atomics.types.operations/atomics.types.operations.req/atomic_is_lock_free.pass.cpp index 4b09c38dbca..4071989204b 100644 --- a/libcxx/test/atomics/atomics.types.operations/atomics.types.operations.req/atomic_is_lock_free.pass.cpp +++ b/libcxx/test/atomics/atomics.types.operations/atomics.types.operations.req/atomic_is_lock_free.pass.cpp @@ -24,10 +24,10 @@ void test() { typedef std::atomic<T> A; - const A ct; - bool b1 = std::atomic_is_lock_free(&ct); - const volatile A cvt; - bool b2 = std::atomic_is_lock_free(&cvt); + A t; + bool b1 = std::atomic_is_lock_free(static_cast<const A*>(&t)); + volatile A vt; + bool b2 = std::atomic_is_lock_free(static_cast<const volatile A*>(&vt)); } struct A |

