Skip to content

Commit 886b761

Browse files
[libc++][test] Fix msvc_is_lock_free_macro_value() (#105876)
Followup to #99570. * `TEST_COMPILER_MSVC` must be tested for `defined`ness, as it is everywhere else. + Definition: https://github.com/llvm/llvm-project/blob/52a7116f5c6ada234f47f7794aaf501a3692b997/libcxx/test/support/test_macros.h#L71-L72 + Example usage: https://github.com/llvm/llvm-project/blob/52a7116f5c6ada234f47f7794aaf501a3692b997/libcxx/test/std/utilities/function.objects/func.not_fn/not_fn.pass.cpp#L248 + Fixes: `llvm-project\libcxx\test\support\atomic_helpers.h(33): fatal error C1017: invalid integer constant expression` * Fix bogus return type: `msvc_is_lock_free_macro_value()` returns `2` or `0`, so it needs to return `int`. + Fixes: `llvm-project\libcxx\test\support\atomic_helpers.h(41): warning C4305: 'return': truncation from 'int' to 'bool'` * Clarity improvement: also add parens when mixing bitwise with arithmetic operators.
1 parent 7036394 commit 886b761

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

libcxx/test/support/atomic_helpers.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@
3030
# define TEST_ATOMIC_LONG_LOCK_FREE __GCC_ATOMIC_LONG_LOCK_FREE
3131
# define TEST_ATOMIC_LLONG_LOCK_FREE __GCC_ATOMIC_LLONG_LOCK_FREE
3232
# define TEST_ATOMIC_POINTER_LOCK_FREE __GCC_ATOMIC_POINTER_LOCK_FREE
33-
#elif TEST_COMPILER_MSVC
33+
#elif defined(TEST_COMPILER_MSVC)
3434
// This is lifted from STL/stl/inc/atomic on github for the purposes of
3535
// keeping the tests compiling for MSVC's STL. It's not a perfect solution
3636
// but at least the tests will keep running.
3737
//
3838
// Note MSVC's STL never produces a type that is sometimes lock free, but not always lock free.
3939
template <class T, size_t Size = sizeof(T)>
40-
constexpr bool msvc_is_lock_free_macro_value() {
41-
return (Size <= 8 && (Size & Size - 1) == 0) ? 2 : 0;
40+
constexpr int msvc_is_lock_free_macro_value() {
41+
return (Size <= 8 && (Size & (Size - 1)) == 0) ? 2 : 0;
4242
}
4343
# define TEST_ATOMIC_CHAR_LOCK_FREE ::msvc_is_lock_free_macro_value<char>()
4444
# define TEST_ATOMIC_SHORT_LOCK_FREE ::msvc_is_lock_free_macro_value<short>()

0 commit comments

Comments
 (0)