Skip to content

Commit bf36a36

Browse files
committed
Attempt 2 to get C++03 atomic test to compile
1 parent f0d6bbf commit bf36a36

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

libcxx/test/support/atomic_helpers.h

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,16 @@ constexpr bool msvc_is_lock_free_macro_value() {
5050
# error "Unknown compiler"
5151
#endif
5252

53+
#ifdef TEST_COMPILER_CLANG
54+
# pragma clang diagnostic push
55+
# pragma clang diagnostic ignored "-Wc++11-extensions"
56+
#endif
5357
// The entire LockFreeStatus/LockFreeStatusEnum/LockFreeStatusType exists entirely to work around the support
5458
// for C++03, which many of our atomic tests run under. This is a bit of a hack, but it's the best we can do.
5559
//
5660
// We could limit the testing involving these things to C++11 or greater? But test coverage in C++03 seems important too.
57-
#if TEST_STD_VER < 11
58-
struct LockFreeStatusEnum {
59-
enum LockFreeStatus { unknown = -1, never = 0, sometimes = 1, always = 2 };
60-
};
61-
typedef LockFreeStatusEnum::LockFreeStatus LockFreeStatus;
62-
#else
61+
6362
enum class LockFreeStatus : int { unknown = -1, never = 0, sometimes = 1, always = 2 };
64-
#endif
6563
#define COMPARE_TYPES(T1, T2) (sizeof(T1) == sizeof(T2) && TEST_ALIGNOF(T1) >= TEST_ALIGNOF(T2))
6664

6765
template <class T>
@@ -79,9 +77,11 @@ struct LockFreeStatusInfo {
7977
? TEST_ATOMIC_LLONG_LOCK_FREE
8078
: (COMPARE_TYPES(T, void*) ? TEST_ATOMIC_POINTER_LOCK_FREE : -1))))));
8179

82-
static const bool status_known = value != LockFreeStatus::unknown;
80+
static const bool status_known = LockFreeStatusInfo::value != LockFreeStatus::unknown;
8381
};
8482

83+
// IDK why this blows up in C++03, but it does. So we'll just disable it.
84+
#if TEST_STD_VER >= 11
8585
static_assert(LockFreeStatusInfo<char>::status_known, "");
8686
static_assert(LockFreeStatusInfo<short>::status_known, "");
8787
static_assert(LockFreeStatusInfo<int>::status_known, "");
@@ -94,6 +94,7 @@ static_assert(LockFreeStatusInfo<char>::value == LockFreeStatus::always, "");
9494
static_assert(LockFreeStatusInfo<short>::value == LockFreeStatus::always, "");
9595
static_assert(LockFreeStatusInfo<int>::value == LockFreeStatus::always,
9696
""); // This one may not always be lock free, but we'll let the CI decide.
97+
#endif
9798

9899
// These macros are somewhat suprising to use, since they take the values 0, 1, or 2.
99100
// To make the tests clearer, get rid of them in preference of AtomicInfo.
@@ -104,6 +105,10 @@ static_assert(LockFreeStatusInfo<int>::value == LockFreeStatus::always,
104105
#undef TEST_ATOMIC_LLONG_LOCK_FREE
105106
#undef TEST_ATOMIC_POINTER_LOCK_FREE
106107

108+
#ifdef TEST_COMPILER_CLANG
109+
# pragma clang diagnostic pop
110+
#endif
111+
107112
struct UserAtomicType {
108113
int i;
109114

0 commit comments

Comments
 (0)