summaryrefslogtreecommitdiffstats
path: root/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_and.pass.cpp
diff options
context:
space:
mode:
authorEric Fiselier <eric@efcs.ca>2015-08-19 17:21:46 +0000
committerEric Fiselier <eric@efcs.ca>2015-08-19 17:21:46 +0000
commit00f4a49b0b76dea78a68ea2dd7333408f52caa5b (patch)
tree22641b8bb87eb240622b48f94acc4507f442ea9a /test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_and.pass.cpp
parent8966350d61a74ade198a57a11efad6c3f1986e38 (diff)
downloadexternal_libcxx-00f4a49b0b76dea78a68ea2dd7333408f52caa5b.tar.gz
external_libcxx-00f4a49b0b76dea78a68ea2dd7333408f52caa5b.tar.bz2
external_libcxx-00f4a49b0b76dea78a68ea2dd7333408f52caa5b.zip
[libcxx] Allow use of <atomic> in C++03. Try 3.
Summary: After putting this question up on cfe-dev I have decided that it would be best to allow the use of `<atomic>` in C++03. Although static initialization is a concern the syntax required to get it is C++11 only. Meaning that C++11 constant static initialization cannot silently break in C++03, it will always cause a syntax error. Furthermore `ATOMIC_VAR_INIT` and `ATOMIC_FLAG_INIT` remain defined in C++03 even though they cannot be used because C++03 usages will cause better error messages. The main change in this patch is to replace `__has_feature(cxx_atomic)`, which only returns true when C++ >= 11, to `__has_extension(c_atomic)` which returns true whenever clang supports the required atomic builtins. This patch adds the following macros: * `_LIBCPP_HAS_C_ATOMIC_IMP` - Defined on clang versions which provide the C `_Atomic` keyword. * `_LIBCPP_HAS_GCC_ATOMIC_IMP` - Defined on GCC > 4.7. We must use the fallback atomic implementation. * `_LIBCPP_HAS_NO_ATOMIC_HEADER` - Defined when it is not safe to include `<atomic>`. `_LIBCPP_HAS_C_ATOMIC_IMP` and `_LIBCPP_HAS_GCC_ATOMIC_IMP` are mutually exclusive, only one should be defined. If neither is defined then `<atomic>` is not implemented and including `<atomic>` will issue an error. Reviewers: chandlerc, jroelofs, mclow.lists Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D11555 git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@245463 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_and.pass.cpp')
-rw-r--r--test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_and.pass.cpp27
1 files changed, 7 insertions, 20 deletions
diff --git a/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_and.pass.cpp b/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_and.pass.cpp
index 4c7c0432e..57355d304 100644
--- a/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_and.pass.cpp
+++ b/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>()();
}