diff options
Diffstat (limited to 'libcxx/test/std/atomics')
30 files changed, 268 insertions, 675 deletions
diff --git a/libcxx/test/std/atomics/atomics.flag/atomic_flag_clear.pass.cpp b/libcxx/test/std/atomics/atomics.flag/atomic_flag_clear.pass.cpp index 8a60f8196da..3a74e13faf1 100644 --- a/libcxx/test/std/atomics/atomics.flag/atomic_flag_clear.pass.cpp +++ b/libcxx/test/std/atomics/atomics.flag/atomic_flag_clear.pass.cpp @@ -22,13 +22,13 @@ int main() { { - std::atomic_flag f = ATOMIC_FLAG_INIT; + std::atomic_flag f(false); f.test_and_set(); atomic_flag_clear(&f); assert(f.test_and_set() == 0); } { - volatile std::atomic_flag f = ATOMIC_FLAG_INIT; + volatile std::atomic_flag f(false); f.test_and_set(); atomic_flag_clear(&f); assert(f.test_and_set() == 0); diff --git a/libcxx/test/std/atomics/atomics.flag/atomic_flag_clear_explicit.pass.cpp b/libcxx/test/std/atomics/atomics.flag/atomic_flag_clear_explicit.pass.cpp index 92e57ecc03f..0467384455c 100644 --- a/libcxx/test/std/atomics/atomics.flag/atomic_flag_clear_explicit.pass.cpp +++ b/libcxx/test/std/atomics/atomics.flag/atomic_flag_clear_explicit.pass.cpp @@ -22,37 +22,37 @@ int main() { { - std::atomic_flag f = ATOMIC_FLAG_INIT; + std::atomic_flag f(false); f.test_and_set(); atomic_flag_clear_explicit(&f, std::memory_order_relaxed); assert(f.test_and_set() == 0); } { - std::atomic_flag f = ATOMIC_FLAG_INIT; + std::atomic_flag f(false); f.test_and_set(); atomic_flag_clear_explicit(&f, std::memory_order_release); assert(f.test_and_set() == 0); } { - std::atomic_flag f = ATOMIC_FLAG_INIT; + std::atomic_flag f(false); f.test_and_set(); atomic_flag_clear_explicit(&f, std::memory_order_seq_cst); assert(f.test_and_set() == 0); } { - volatile std::atomic_flag f = ATOMIC_FLAG_INIT; + volatile std::atomic_flag f(false); f.test_and_set(); atomic_flag_clear_explicit(&f, std::memory_order_relaxed); assert(f.test_and_set() == 0); } { - volatile std::atomic_flag f = ATOMIC_FLAG_INIT; + volatile std::atomic_flag f(false); f.test_and_set(); atomic_flag_clear_explicit(&f, std::memory_order_release); assert(f.test_and_set() == 0); } { - volatile std::atomic_flag f = ATOMIC_FLAG_INIT; + volatile std::atomic_flag f(false); f.test_and_set(); atomic_flag_clear_explicit(&f, std::memory_order_seq_cst); assert(f.test_and_set() == 0); diff --git a/libcxx/test/std/atomics/atomics.flag/clear.pass.cpp b/libcxx/test/std/atomics/atomics.flag/clear.pass.cpp index 7c9362680bb..ea5ae45ae99 100644 --- a/libcxx/test/std/atomics/atomics.flag/clear.pass.cpp +++ b/libcxx/test/std/atomics/atomics.flag/clear.pass.cpp @@ -22,49 +22,49 @@ int main() { { - std::atomic_flag f = ATOMIC_FLAG_INIT; + std::atomic_flag f(false); f.test_and_set(); f.clear(); assert(f.test_and_set() == 0); } { - std::atomic_flag f = ATOMIC_FLAG_INIT; + std::atomic_flag f(false); f.test_and_set(); f.clear(std::memory_order_relaxed); assert(f.test_and_set() == 0); } { - std::atomic_flag f = ATOMIC_FLAG_INIT; + std::atomic_flag f(false); f.test_and_set(); f.clear(std::memory_order_release); assert(f.test_and_set() == 0); } { - std::atomic_flag f = ATOMIC_FLAG_INIT; + std::atomic_flag f(false); f.test_and_set(); f.clear(std::memory_order_seq_cst); assert(f.test_and_set() == 0); } { - volatile std::atomic_flag f = ATOMIC_FLAG_INIT; + volatile std::atomic_flag f(false); f.test_and_set(); f.clear(); assert(f.test_and_set() == 0); } { - volatile std::atomic_flag f = ATOMIC_FLAG_INIT; + volatile std::atomic_flag f(false); f.test_and_set(); f.clear(std::memory_order_relaxed); assert(f.test_and_set() == 0); } { - volatile std::atomic_flag f = ATOMIC_FLAG_INIT; + volatile std::atomic_flag f(false); f.test_and_set(); f.clear(std::memory_order_release); assert(f.test_and_set() == 0); } { - volatile std::atomic_flag f = ATOMIC_FLAG_INIT; + volatile std::atomic_flag f(false); f.test_and_set(); f.clear(std::memory_order_seq_cst); assert(f.test_and_set() == 0); diff --git a/libcxx/test/std/atomics/atomics.flag/init.pass.cpp b/libcxx/test/std/atomics/atomics.flag/init.pass.cpp index c90509d8fbb..c4a121b094a 100644 --- a/libcxx/test/std/atomics/atomics.flag/init.pass.cpp +++ b/libcxx/test/std/atomics/atomics.flag/init.pass.cpp @@ -8,6 +8,7 @@ //===----------------------------------------------------------------------===// // // UNSUPPORTED: libcpp-has-no-threads +// XFAIL: c++98, c++03 // <atomic> diff --git a/libcxx/test/std/atomics/atomics.flag/init03.pass.cpp b/libcxx/test/std/atomics/atomics.flag/init03.pass.cpp new file mode 100644 index 00000000000..0910bc5cecc --- /dev/null +++ b/libcxx/test/std/atomics/atomics.flag/init03.pass.cpp @@ -0,0 +1,25 @@ +//===----------------------------------------------------------------------===// +// +// 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 + +// <atomic> + +// struct atomic_flag + +// TESTING EXTENSION atomic_flag(bool) + +#include <atomic> +#include <cassert> + +int main() +{ + std::atomic_flag f(false); + assert(f.test_and_set() == 0); +} diff --git a/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_compare_exchange_strong.pass.cpp b/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_compare_exchange_strong.pass.cpp index f1cc993ed33..7b221dc6eff 100644 --- a/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_compare_exchange_strong.pass.cpp +++ b/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_compare_exchange_strong.pass.cpp @@ -24,10 +24,11 @@ #include <type_traits> #include <cassert> +#include "atomic_helpers.h" + template <class T> -void -test() -{ +struct TestFn { + void operator()() const { { typedef std::atomic<T> A; A a; @@ -52,37 +53,10 @@ test() assert(a == T(2)); assert(t == T(2)); } -} - -struct A -{ - int i; - - explicit A(int d = 0) noexcept {i=d;} - - friend bool operator==(const A& x, const A& y) - {return x.i == y.i;} + } }; int main() { - test<A>(); - test<char>(); - test<signed char>(); - test<unsigned char>(); - test<short>(); - test<unsigned short>(); - test<int>(); - test<unsigned int>(); - test<long>(); - test<unsigned long>(); - test<long long>(); - test<unsigned long long>(); - test<wchar_t>(); -#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS - test<char16_t>(); - test<char32_t>(); -#endif // _LIBCPP_HAS_NO_UNICODE_CHARS - test<int*>(); - test<const int*>(); + TestEachAtomicType<TestFn>()(); } diff --git a/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_compare_exchange_strong_explicit.pass.cpp b/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_compare_exchange_strong_explicit.pass.cpp index f667ab7f139..27de5bec492 100644 --- a/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_compare_exchange_strong_explicit.pass.cpp +++ b/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_compare_exchange_strong_explicit.pass.cpp @@ -27,10 +27,11 @@ #include <type_traits> #include <cassert> +#include "atomic_helpers.h" + template <class T> -void -test() -{ +struct TestFn { + void operator()() const { { typedef std::atomic<T> A; A a; @@ -59,37 +60,10 @@ test() assert(a == T(2)); assert(t == T(2)); } -} - -struct A -{ - int i; - - explicit A(int d = 0) noexcept {i=d;} - - friend bool operator==(const A& x, const A& y) - {return x.i == y.i;} + } }; int main() { - test<A>(); - test<char>(); - test<signed char>(); - test<unsigned char>(); - test<short>(); - test<unsigned short>(); - test<int>(); - test<unsigned int>(); - test<long>(); - test<unsigned long>(); - test<long long>(); - test<unsigned long long>(); - test<wchar_t>(); -#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS - test<char16_t>(); - test<char32_t>(); -#endif // _LIBCPP_HAS_NO_UNICODE_CHARS - test<int*>(); - test<const int*>(); + TestEachAtomicType<TestFn>()(); } diff --git a/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_compare_exchange_weak.pass.cpp b/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_compare_exchange_weak.pass.cpp index 175c445d456..8c12715647e 100644 --- a/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_compare_exchange_weak.pass.cpp +++ b/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_compare_exchange_weak.pass.cpp @@ -25,11 +25,11 @@ #include <cassert> #include <cmpxchg_loop.h> +#include "atomic_helpers.h" template <class T> -void -test() -{ +struct TestFn { + void operator()() const { { typedef std::atomic<T> A; A a; @@ -54,37 +54,10 @@ test() assert(a == T(2)); assert(t == T(2)); } -} - -struct A -{ - int i; - - explicit A(int d = 0) noexcept {i=d;} - - friend bool operator==(const A& x, const A& y) - {return x.i == y.i;} + } }; int main() { - test<A>(); - test<char>(); - test<signed char>(); - test<unsigned char>(); - test<short>(); - test<unsigned short>(); - test<int>(); - test<unsigned int>(); - test<long>(); - test<unsigned long>(); - test<long long>(); - test<unsigned long long>(); - test<wchar_t>(); -#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS - test<char16_t>(); - test<char32_t>(); -#endif // _LIBCPP_HAS_NO_UNICODE_CHARS - test<int*>(); - test<const int*>(); + TestEachAtomicType<TestFn>()(); } diff --git a/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_compare_exchange_weak_explicit.pass.cpp b/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_compare_exchange_weak_explicit.pass.cpp index 46f80bfbcb7..90a93f02b97 100644 --- a/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_compare_exchange_weak_explicit.pass.cpp +++ b/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_compare_exchange_weak_explicit.pass.cpp @@ -29,10 +29,11 @@ #include <cmpxchg_loop.h> +#include "atomic_helpers.h" + template <class T> -void -test() -{ +struct TestFn { + void operator()() const { { typedef std::atomic<T> A; A a; @@ -61,37 +62,10 @@ test() assert(a == T(2)); assert(t == T(2)); } -} - -struct A -{ - int i; - - explicit A(int d = 0) noexcept {i=d;} - - friend bool operator==(const A& x, const A& y) - {return x.i == y.i;} + } }; int main() { - test<A>(); - test<char>(); - test<signed char>(); - test<unsigned char>(); - test<short>(); - test<unsigned short>(); - test<int>(); - test<unsigned int>(); - test<long>(); - test<unsigned long>(); - test<long long>(); - test<unsigned long long>(); - test<wchar_t>(); -#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS - test<char16_t>(); - test<char32_t>(); -#endif // _LIBCPP_HAS_NO_UNICODE_CHARS - test<int*>(); - test<const int*>(); + TestEachAtomicType<TestFn>()(); } diff --git a/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_exchange.pass.cpp b/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_exchange.pass.cpp index 525e74aa637..035d974427a 100644 --- a/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_exchange.pass.cpp +++ b/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_exchange.pass.cpp @@ -24,10 +24,11 @@ #include <type_traits> #include <cassert> +#include "atomic_helpers.h" + template <class T> -void -test() -{ +struct TestFn { + void operator()() const { typedef std::atomic<T> A; A t; std::atomic_init(&t, T(1)); @@ -37,37 +38,11 @@ test() std::atomic_init(&vt, T(3)); assert(std::atomic_exchange(&vt, T(4)) == T(3)); assert(vt == T(4)); -} - -struct A -{ - int i; - - explicit A(int d = 0) noexcept {i=d;} - - friend bool operator==(const A& x, const A& y) - {return x.i == y.i;} + } }; + int main() { - test<A>(); - test<char>(); - test<signed char>(); - test<unsigned char>(); - test<short>(); - test<unsigned short>(); - test<int>(); - test<unsigned int>(); - test<long>(); - test<unsigned long>(); - test<long long>(); - test<unsigned long long>(); - test<wchar_t>(); -#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS - test<char16_t>(); - test<char32_t>(); -#endif // _LIBCPP_HAS_NO_UNICODE_CHARS - test<int*>(); - test<const int*>(); + TestEachAtomicType<TestFn>()(); } diff --git a/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_exchange_explicit.pass.cpp b/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_exchange_explicit.pass.cpp index 9fe4ac81644..4d66bb5f3b8 100644 --- a/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_exchange_explicit.pass.cpp +++ b/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_exchange_explicit.pass.cpp @@ -24,10 +24,11 @@ #include <type_traits> #include <cassert> +#include "atomic_helpers.h" + template <class T> -void -test() -{ +struct TestFn { + void operator()() const { typedef std::atomic<T> A; A t; std::atomic_init(&t, T(1)); @@ -39,37 +40,11 @@ test() assert(std::atomic_exchange_explicit(&vt, T(4), std::memory_order_seq_cst) == T(3)); assert(vt == T(4)); -} - -struct A -{ - int i; - - explicit A(int d = 0) noexcept {i=d;} - - friend bool operator==(const A& x, const A& y) - {return x.i == y.i;} + } }; + int main() { - test<A>(); - test<char>(); - test<signed char>(); - test<unsigned char>(); - test<short>(); - test<unsigned short>(); - test<int>(); - test<unsigned int>(); - test<long>(); - test<unsigned long>(); - test<long long>(); - test<unsigned long long>(); - test<wchar_t>(); -#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS - test<char16_t>(); - test<char32_t>(); -#endif // _LIBCPP_HAS_NO_UNICODE_CHARS - test<int*>(); - test<const int*>(); + TestEachAtomicType<TestFn>()(); } diff --git a/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_add.pass.cpp b/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_add.pass.cpp index 3408def9058..48ff601539c 100644 --- a/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_add.pass.cpp +++ b/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_add.pass.cpp @@ -32,10 +32,11 @@ #include <type_traits> #include <cassert> +#include "atomic_helpers.h" + template <class T> -void -test() -{ +struct TestFn { + void operator()() const { { typedef std::atomic<T> A; A t; @@ -50,11 +51,11 @@ test() assert(std::atomic_fetch_add(&t, T(2)) == T(1)); assert(t == T(3)); } -} + } +}; template <class T> -void -testp() +void testp() { { typedef std::atomic<T> A; @@ -74,38 +75,9 @@ testp() } } -struct A -{ - int i; - - explicit A(int d = 0) noexcept {i=d;} - A(const A& a) : i(a.i) {} - A(const volatile A& a) : i(a.i) {} - - void operator=(const volatile A& a) volatile {i = a.i;} - - friend bool operator==(const A& x, const A& y) - {return x.i == y.i;} -}; - int main() { - test<char>(); - test<signed char>(); - test<unsigned char>(); - test<short>(); - test<unsigned short>(); - test<int>(); - test<unsigned int>(); - test<long>(); - test<unsigned long>(); - test<long long>(); - test<unsigned long long>(); - test<wchar_t>(); -#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS - test<char16_t>(); - test<char32_t>(); -#endif // _LIBCPP_HAS_NO_UNICODE_CHARS + TestEachIntegralType<TestFn>()(); testp<int*>(); testp<const int*>(); } diff --git a/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_add_explicit.pass.cpp b/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_add_explicit.pass.cpp index 9977bd491e7..2dc90c9aca6 100644 --- a/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_add_explicit.pass.cpp +++ b/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_add_explicit.pass.cpp @@ -32,10 +32,11 @@ #include <type_traits> #include <cassert> +#include "atomic_helpers.h" + template <class T> -void -test() -{ +struct TestFn { + void operator()() const { { typedef std::atomic<T> A; A t; @@ -52,7 +53,8 @@ test() std::memory_order_seq_cst) == T(1)); assert(t == T(3)); } -} + } +}; template <class T> void @@ -78,38 +80,9 @@ testp() } } -struct A -{ - int i; - - explicit A(int d = 0) noexcept {i=d;} - A(const A& a) : i(a.i) {} - A(const volatile A& a) : i(a.i) {} - - void operator=(const volatile A& a) volatile {i = a.i;} - - friend bool operator==(const A& x, const A& y) - {return x.i == y.i;} -}; - int main() { - test<char>(); - test<signed char>(); - test<unsigned char>(); - test<short>(); - test<unsigned short>(); - test<int>(); - test<unsigned int>(); - test<long>(); - test<unsigned long>(); - test<long long>(); - test<unsigned long long>(); - test<wchar_t>(); -#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS - test<char16_t>(); - test<char32_t>(); -#endif // _LIBCPP_HAS_NO_UNICODE_CHARS + TestEachIntegralType<TestFn>()(); testp<int*>(); testp<const int*>(); } diff --git a/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_and.pass.cpp b/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_and.pass.cpp index 4c7c0432efc..57355d30411 100644 --- a/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_and.pass.cpp +++ b/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_and.pass.cpp @@ -23,10 +23,11 @@ #include <type_traits> #include <cassert> +#include "atomic_helpers.h" + template <class T> -void -test() -{ +struct TestFn { + void operator()() const { { typedef std::atomic<T> A; A t; @@ -41,24 +42,10 @@ test() assert(std::atomic_fetch_and(&t, T(2)) == T(3)); assert(t == T(2)); } -} + } +}; int main() { - test<char>(); - test<signed char>(); - test<unsigned char>(); - test<short>(); - test<unsigned short>(); - test<int>(); - test<unsigned int>(); - test<long>(); - test<unsigned long>(); - test<long long>(); - test<unsigned long long>(); - test<wchar_t>(); -#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS - test<char16_t>(); - test<char32_t>(); -#endif // _LIBCPP_HAS_NO_UNICODE_CHARS + TestEachIntegralType<TestFn>()(); } diff --git a/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_and_explicit.pass.cpp b/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_and_explicit.pass.cpp index d83bbf264de..26ff5f65e7d 100644 --- a/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_and_explicit.pass.cpp +++ b/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_and_explicit.pass.cpp @@ -23,10 +23,11 @@ #include <type_traits> #include <cassert> +#include "atomic_helpers.h" + template <class T> -void -test() -{ +struct TestFn { + void operator()() const { { typedef std::atomic<T> A; A t; @@ -43,24 +44,10 @@ test() std::memory_order_seq_cst) == T(3)); assert(t == T(2)); } -} + } +}; int main() { - test<char>(); - test<signed char>(); - test<unsigned char>(); - test<short>(); - test<unsigned short>(); - test<int>(); - test<unsigned int>(); - test<long>(); - test<unsigned long>(); - test<long long>(); - test<unsigned long long>(); - test<wchar_t>(); -#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS - test<char16_t>(); - test<char32_t>(); -#endif // _LIBCPP_HAS_NO_UNICODE_CHARS + TestEachIntegralType<TestFn>()(); } diff --git a/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_or.pass.cpp b/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_or.pass.cpp index acf6d439de4..ca44fdc3217 100644 --- a/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_or.pass.cpp +++ b/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_or.pass.cpp @@ -23,10 +23,11 @@ #include <type_traits> #include <cassert> +#include "atomic_helpers.h" + template <class T> -void -test() -{ +struct TestFn { + void operator()() const { { typedef std::atomic<T> A; A t; @@ -41,24 +42,10 @@ test() assert(std::atomic_fetch_or(&t, T(2)) == T(3)); assert(t == T(3)); } -} + } +}; int main() { - test<char>(); - test<signed char>(); - test<unsigned char>(); - test<short>(); - test<unsigned short>(); - test<int>(); - test<unsigned int>(); - test<long>(); - test<unsigned long>(); - test<long long>(); - test<unsigned long long>(); - test<wchar_t>(); -#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS - test<char16_t>(); - test<char32_t>(); -#endif // _LIBCPP_HAS_NO_UNICODE_CHARS + TestEachIntegralType<TestFn>()(); } diff --git a/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_or_explicit.pass.cpp b/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_or_explicit.pass.cpp index 72685e4d940..72bbde798cb 100644 --- a/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_or_explicit.pass.cpp +++ b/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_or_explicit.pass.cpp @@ -23,10 +23,11 @@ #include <type_traits> #include <cassert> +#include "atomic_helpers.h" + template <class T> -void -test() -{ +struct TestFn { + void operator()() const { { typedef std::atomic<T> A; A t; @@ -43,24 +44,10 @@ test() std::memory_order_seq_cst) == T(3)); assert(t == T(3)); } -} + } +}; int main() { - test<char>(); - test<signed char>(); - test<unsigned char>(); - test<short>(); - test<unsigned short>(); - test<int>(); - test<unsigned int>(); - test<long>(); - test<unsigned long>(); - test<long long>(); - test<unsigned long long>(); - test<wchar_t>(); -#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS - test<char16_t>(); - test<char32_t>(); -#endif // _LIBCPP_HAS_NO_UNICODE_CHARS + TestEachIntegralType<TestFn>()(); } diff --git a/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_sub.pass.cpp b/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_sub.pass.cpp index ed8b541291a..2743040428c 100644 --- a/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_sub.pass.cpp +++ b/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_sub.pass.cpp @@ -32,10 +32,11 @@ #include <type_traits> #include <cassert> +#include "atomic_helpers.h" + template <class T> -void -test() -{ +struct TestFn { + void operator()() const { { typedef std::atomic<T> A; A t; @@ -50,11 +51,11 @@ test() assert(std::atomic_fetch_sub(&t, T(2)) == T(3)); assert(t == T(1)); } -} + } +}; template <class T> -void -testp() +void testp() { { typedef std::atomic<T> A; @@ -74,38 +75,9 @@ testp() } } -struct A -{ - int i; - - explicit A(int d = 0) noexcept {i=d;} - A(const A& a) : i(a.i) {} - A(const volatile A& a) : i(a.i) {} - - void operator=(const volatile A& a) volatile {i = a.i;} - - friend bool operator==(const A& x, const A& y) - {return x.i == y.i;} -}; - int main() { - test<char>(); - test<signed char>(); - test<unsigned char>(); - test<short>(); - test<unsigned short>(); - test<int>(); - test<unsigned int>(); - test<long>(); - test<unsigned long>(); - test<long long>(); - test<unsigned long long>(); - test<wchar_t>(); -#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS - test<char16_t>(); - test<char32_t>(); -#endif // _LIBCPP_HAS_NO_UNICODE_CHARS + TestEachIntegralType<TestFn>()(); testp<int*>(); testp<const int*>(); } diff --git a/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_sub_explicit.pass.cpp b/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_sub_explicit.pass.cpp index e6c92eada6d..6e94c505fd8 100644 --- a/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_sub_explicit.pass.cpp +++ b/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_sub_explicit.pass.cpp @@ -33,10 +33,11 @@ #include <type_traits> #include <cassert> +#include "atomic_helpers.h" + template <class T> -void -test() -{ +struct TestFn { + void operator()() const { { typedef std::atomic<T> A; A t; @@ -53,11 +54,11 @@ test() std::memory_order_seq_cst) == T(3)); assert(t == T(1)); } -} + } +}; template <class T> -void -testp() +void testp() { { typedef std::atomic<T> A; @@ -79,38 +80,9 @@ testp() } } -struct A -{ - int i; - - explicit A(int d = 0) noexcept {i=d;} - A(const A& a) : i(a.i) {} - A(const volatile A& a) : i(a.i) {} - - void operator=(const volatile A& a) volatile {i = a.i;} - - friend bool operator==(const A& x, const A& y) - {return x.i == y.i;} -}; - int main() { - test<char>(); - test<signed char>(); - test<unsigned char>(); - test<short>(); - test<unsigned short>(); - test<int>(); - test<unsigned int>(); - test<long>(); - test<unsigned long>(); - test<long long>(); - test<unsigned long long>(); - test<wchar_t>(); -#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS - test<char16_t>(); - test<char32_t>(); -#endif // _LIBCPP_HAS_NO_UNICODE_CHARS + TestEachIntegralType<TestFn>()(); testp<int*>(); testp<const int*>(); } diff --git a/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_xor.pass.cpp b/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_xor.pass.cpp index fc6b97b7db4..42d57dedbd1 100644 --- a/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_xor.pass.cpp +++ b/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_xor.pass.cpp @@ -23,10 +23,11 @@ #include <type_traits> #include <cassert> +#include "atomic_helpers.h" + template <class T> -void -test() -{ +struct TestFn { + void operator()() const { { typedef std::atomic<T> A; A t; @@ -41,24 +42,10 @@ test() assert(std::atomic_fetch_xor(&t, T(2)) == T(3)); assert(t == T(1)); } -} + } +}; int main() { - test<char>(); - test<signed char>(); - test<unsigned char>(); - test<short>(); - test<unsigned short>(); - test<int>(); - test<unsigned int>(); - test<long>(); - test<unsigned long>(); - test<long long>(); - test<unsigned long long>(); - test<wchar_t>(); -#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS - test<char16_t>(); - test<char32_t>(); -#endif // _LIBCPP_HAS_NO_UNICODE_CHARS + TestEachIntegralType<TestFn>()(); } diff --git a/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_xor_explicit.pass.cpp b/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_xor_explicit.pass.cpp index 58772aa4d15..8f388fee632 100644 --- a/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_xor_explicit.pass.cpp +++ b/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_xor_explicit.pass.cpp @@ -23,10 +23,11 @@ #include <type_traits> #include <cassert> +#include "atomic_helpers.h" + template <class T> -void -test() -{ +struct TestFn { + void operator()() const { { typedef std::atomic<T> A; A t; @@ -43,24 +44,10 @@ test() std::memory_order_seq_cst) == T(3)); assert(t == T(1)); } -} + } +}; int main() { - test<char>(); - test<signed char>(); - test<unsigned char>(); - test<short>(); - test<unsigned short>(); - test<int>(); - test<unsigned int>(); - test<long>(); - test<unsigned long>(); - test<long long>(); - test<unsigned long long>(); - test<wchar_t>(); -#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS - test<char16_t>(); - test<char32_t>(); -#endif // _LIBCPP_HAS_NO_UNICODE_CHARS + TestEachIntegralType<TestFn>()(); } diff --git a/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_helpers.h b/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_helpers.h new file mode 100644 index 00000000000..e31420b156c --- /dev/null +++ b/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_helpers.h @@ -0,0 +1,51 @@ +#ifndef ATOMIC_HELPERS_H +#define ATOMIC_HELPERS_H + +#include <cassert> + +#include "test_macros.h" + +struct UserAtomicType +{ + int i; + + explicit UserAtomicType(int d = 0) TEST_NOEXCEPT : i(d) {} + + friend bool operator==(const UserAtomicType& x, const UserAtomicType& y) + { return x.i == y.i; } +}; + +template < template <class TestArg> class TestFunctor > +struct TestEachIntegralType { + void operator()() const { + TestFunctor<char>()(); + TestFunctor<signed char>()(); + TestFunctor<unsigned char>()(); + TestFunctor<short>()(); + TestFunctor<unsigned short>()(); + TestFunctor<int>()(); + TestFunctor<unsigned int>()(); + TestFunctor<long>()(); + TestFunctor<unsigned long>()(); + TestFunctor<long long>()(); + TestFunctor<unsigned long long>()(); + TestFunctor<wchar_t>(); +#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS + TestFunctor<char16_t>()(); + TestFunctor<char32_t>()(); +#endif + } +}; + +template < template <class TestArg> class TestFunctor > +struct TestEachAtomicType { + void operator()() const { + TestEachIntegralType<TestFunctor>()(); + TestFunctor<UserAtomicType>()(); + TestFunctor<int*>()(); + TestFunctor<const int*>()(); + } +}; + + +#endif // ATOMIC_HELPER_H diff --git a/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_init.pass.cpp b/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_init.pass.cpp index 137b6f60f74..884c02dfe7e 100644 --- a/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_init.pass.cpp +++ b/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_init.pass.cpp @@ -8,7 +8,7 @@ //===----------------------------------------------------------------------===// // // UNSUPPORTED: libcpp-has-no-threads -// ... assertion fails line 34 +// ... assertion fails line 36 // <atomic> @@ -24,10 +24,11 @@ #include <type_traits> #include <cassert> +#include "atomic_helpers.h" + template <class T> -void -test() -{ +struct TestFn { + void operator()() const { typedef std::atomic<T> A; A t; std::atomic_init(&t, T(1)); @@ -35,37 +36,10 @@ test() volatile A vt; std::atomic_init(&vt, T(2)); assert(vt == T(2)); -} - -struct A -{ - int i; - - explicit A(int d = 0) noexcept {i=d;} - - friend bool operator==(const A& x, const A& y) - {return x.i == y.i;} + } }; int main() { - test<A>(); - test<char>(); - test<signed char>(); - test<unsigned char>(); - test<short>(); - test<unsigned short>(); - test<int>(); - test<unsigned int>(); - test<long>(); - test<unsigned long>(); - test<long long>(); - test<unsigned long long>(); - test<wchar_t>(); -#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS - test<char16_t>(); - test<char32_t>(); -#endif // _LIBCPP_HAS_NO_UNICODE_CHARS - test<int*>(); - test<const int*>(); + TestEachAtomicType<TestFn>()(); } diff --git a/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_is_lock_free.pass.cpp b/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_is_lock_free.pass.cpp index ee229120a62..5d50016ed32 100644 --- a/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_is_lock_free.pass.cpp +++ b/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_is_lock_free.pass.cpp @@ -22,17 +22,19 @@ #include <atomic> #include <cassert> +#include "atomic_helpers.h" + template <class T> -void -test() -{ +struct TestFn { + void operator()() const { typedef std::atomic<T> A; 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)); assert(b1 == b2); -} + } +}; struct A { @@ -41,23 +43,6 @@ struct A int main() { - test<A>(); - test<char>(); - test<signed char>(); - test<unsigned char>(); - test<short>(); - test<unsigned short>(); - test<int>(); - test<unsigned int>(); - test<long>(); - test<unsigned long>(); - test<long long>(); - test<unsigned long long>(); - test<wchar_t>(); -#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS - test<char16_t>(); - test<char32_t>(); -#endif // _LIBCPP_HAS_NO_UNICODE_CHARS - test<int*>(); - test<const int*>(); + TestFn<A>()(); + TestEachAtomicType<TestFn>()(); } diff --git a/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_load.pass.cpp b/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_load.pass.cpp index 66918c71f1f..e7b8e64b434 100644 --- a/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_load.pass.cpp +++ b/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_load.pass.cpp @@ -8,7 +8,7 @@ //===----------------------------------------------------------------------===// // // UNSUPPORTED: libcpp-has-no-threads -// ... assertion fails line 34 +// ... assertion fails line 35 // <atomic> @@ -24,10 +24,11 @@ #include <type_traits> #include <cassert> +#include "atomic_helpers.h" + template <class T> -void -test() -{ +struct TestFn { + void operator()() const { typedef std::atomic<T> A; A t; std::atomic_init(&t, T(1)); @@ -35,37 +36,10 @@ test() volatile A vt; std::atomic_init(&vt, T(2)); assert(std::atomic_load(&vt) == T(2)); -} - -struct A -{ - int i; - - explicit A(int d = 0) noexcept {i=d;} - - friend bool operator==(const A& x, const A& y) - {return x.i == y.i;} + } }; int main() { - test<A>(); - test<char>(); - test<signed char>(); - test<unsigned char>(); - test<short>(); - test<unsigned short>(); - test<int>(); - test<unsigned int>(); - test<long>(); - test<unsigned long>(); - test<long long>(); - test<unsigned long long>(); - test<wchar_t>(); -#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS - test<char16_t>(); - test<char32_t>(); -#endif // _LIBCPP_HAS_NO_UNICODE_CHARS - test<int*>(); - test<const int*>(); + TestEachAtomicType<TestFn>()(); } diff --git a/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_load_explicit.pass.cpp b/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_load_explicit.pass.cpp index 5f402a9f139..56533fa871e 100644 --- a/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_load_explicit.pass.cpp +++ b/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_load_explicit.pass.cpp @@ -24,10 +24,11 @@ #include <type_traits> #include <cassert> +#include "atomic_helpers.h" + template <class T> -void -test() -{ +struct TestFn { + void operator()() const { typedef std::atomic<T> A; A t; std::atomic_init(&t, T(1)); @@ -35,37 +36,10 @@ test() volatile A vt; std::atomic_init(&vt, T(2)); assert(std::atomic_load_explicit(&vt, std::memory_order_seq_cst) == T(2)); -} - -struct A -{ - int i; - - explicit A(int d = 0) noexcept {i=d;} - - friend bool operator==(const A& x, const A& y) - {return x.i == y.i;} + } }; int main() { - test<A>(); - test<char>(); - test<signed char>(); - test<unsigned char>(); - test<short>(); - test<unsigned short>(); - test<int>(); - test<unsigned int>(); - test<long>(); - test<unsigned long>(); - test<long long>(); - test<unsigned long long>(); - test<wchar_t>(); -#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS - test<char16_t>(); - test<char32_t>(); -#endif // _LIBCPP_HAS_NO_UNICODE_CHARS - test<int*>(); - test<const int*>(); + TestEachAtomicType<TestFn>()(); } diff --git a/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_store.pass.cpp b/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_store.pass.cpp index 2b9582b3c52..e61dae90411 100644 --- a/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_store.pass.cpp +++ b/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_store.pass.cpp @@ -8,7 +8,6 @@ //===----------------------------------------------------------------------===// // // UNSUPPORTED: libcpp-has-no-threads -// ... assertion fails line 31 // <atomic> @@ -24,10 +23,11 @@ #include <type_traits> #include <cassert> +#include "atomic_helpers.h" + template <class T> -void -test() -{ +struct TestFn { + void operator()() const { typedef std::atomic<T> A; A t; std::atomic_store(&t, T(1)); @@ -35,37 +35,11 @@ test() volatile A vt; std::atomic_store(&vt, T(2)); assert(vt == T(2)); -} - -struct A -{ - int i; - - explicit A(int d = 0) noexcept {i=d;} - - friend bool operator==(const A& x, const A& y) - {return x.i == y.i;} + } }; + int main() { - test<A>(); - test<char>(); - test<signed char>(); - test<unsigned char>(); - test<short>(); - test<unsigned short>(); - test<int>(); - test<unsigned int>(); - test<long>(); - test<unsigned long>(); - test<long long>(); - test<unsigned long long>(); - test<wchar_t>(); -#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS - test<char16_t>(); - test<char32_t>(); -#endif // _LIBCPP_HAS_NO_UNICODE_CHARS - test<int*>(); - test<const int*>(); + TestEachAtomicType<TestFn>()(); } diff --git a/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_store_explicit.pass.cpp b/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_store_explicit.pass.cpp index 8fe0c7d8842..e57cf8b1b32 100644 --- a/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_store_explicit.pass.cpp +++ b/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_store_explicit.pass.cpp @@ -8,7 +8,6 @@ //===----------------------------------------------------------------------===// // // UNSUPPORTED: libcpp-has-no-threads -// ... assertion fails line 31 // <atomic> @@ -24,10 +23,11 @@ #include <type_traits> #include <cassert> +#include "atomic_helpers.h" + template <class T> -void -test() -{ +struct TestFn { + void operator()() const { typedef std::atomic<T> A; A t; std::atomic_store_explicit(&t, T(1), std::memory_order_seq_cst); @@ -35,37 +35,11 @@ test() volatile A vt; std::atomic_store_explicit(&vt, T(2), std::memory_order_seq_cst); assert(vt == T(2)); -} - -struct A -{ - int i; - - explicit A(int d = 0) noexcept {i=d;} - - friend bool operator==(const A& x, const A& y) - {return x.i == y.i;} + } }; + int main() { - test<A>(); - test<char>(); - test<signed char>(); - test<unsigned char>(); - test<short>(); - test<unsigned short>(); - test<int>(); - test<unsigned int>(); - test<long>(); - test<unsigned long>(); - test<long long>(); - test<unsigned long long>(); - test<wchar_t>(); -#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS - test<char16_t>(); - test<char32_t>(); -#endif // _LIBCPP_HAS_NO_UNICODE_CHARS - test<int*>(); - test<const int*>(); + TestEachAtomicType<TestFn>()(); } diff --git a/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_var_init.pass.cpp b/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_var_init.pass.cpp index 5fed691da26..9f25807fbcd 100644 --- a/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_var_init.pass.cpp +++ b/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_var_init.pass.cpp @@ -8,6 +8,7 @@ //===----------------------------------------------------------------------===// // // UNSUPPORTED: libcpp-has-no-threads +// XFAIL: c++98, c++03 // <atomic> diff --git a/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/ctor.pass.cpp b/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/ctor.pass.cpp index f85172a0149..f6944c7255b 100644 --- a/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/ctor.pass.cpp +++ b/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/ctor.pass.cpp @@ -22,6 +22,8 @@ #include <type_traits> #include <cassert> +#include "atomic_helpers.h" + struct UserType { int i; @@ -34,27 +36,29 @@ struct UserType { }; template <class Tp> -void test() { - typedef std::atomic<Tp> Atomic; - static_assert(std::is_literal_type<Atomic>::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); +struct TestFunc { + void operator()() const { + typedef std::atomic<Tp> Atomic; + static_assert(std::is_literal_type<Atomic>::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<int>(); - test<UserType>(); + TestFunc<UserType>()(); + TestEachIntegralType<TestFunc>()(); } |