Skip to content

Commit 04576cc

Browse files
committedJan 10, 2018
[libcxx] [test] Improve MSVC portability.
test/support/msvc_stdlib_force_include.hpp When testing MSVC's STL with C1XX, simulate a couple more compiler feature-test macros. When testing MSVC's STL, simulate a few library feature-test macros. test/std/atomics/atomics.lockfree/isalwayslockfree.pass.cpp The vector_size attribute is a non-Standard extension that's supported by Clang and GCC, but not C1XX. Therefore, guard this with `__has_attribute(vector_size)`. Additionally, while these tests pass when MSVC's STL is compiled with Clang, I don't consider this to be a supported scenario for our library, so also guard this with defined(_LIBCPP_VERSION). test/std/utilities/function.objects/func.not_fn/not_fn.pass.cpp N4713 23.14.10 [func.not_fn]/1 depicts only `call_wrapper(call_wrapper&&) = default;` and `call_wrapper(const call_wrapper&) = default;`. According to 15.8.2 [class.copy.assign]/2 and /4, this makes call_wrapper non-assignable. Therefore, guard the assignability tests as libc++ specific. Add a (void) cast to tolerate not_fn() being marked as nodiscard. Fixes D41213. llvm-svn: 322144
1 parent 88e9a15 commit 04576cc

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed
 

‎libcxx/test/std/atomics/atomics.lockfree/isalwayslockfree.pass.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ int main()
8989
CHECK_ALWAYS_LOCK_FREE(float);
9090
CHECK_ALWAYS_LOCK_FREE(double);
9191
CHECK_ALWAYS_LOCK_FREE(long double);
92+
#if __has_attribute(vector_size) && defined(_LIBCPP_VERSION)
9293
CHECK_ALWAYS_LOCK_FREE(int __attribute__((vector_size(1 * sizeof(int)))));
9394
CHECK_ALWAYS_LOCK_FREE(int __attribute__((vector_size(2 * sizeof(int)))));
9495
CHECK_ALWAYS_LOCK_FREE(int __attribute__((vector_size(4 * sizeof(int)))));
@@ -104,6 +105,7 @@ int main()
104105
CHECK_ALWAYS_LOCK_FREE(double __attribute__((vector_size(4 * sizeof(double)))));
105106
CHECK_ALWAYS_LOCK_FREE(double __attribute__((vector_size(16 * sizeof(double)))));
106107
CHECK_ALWAYS_LOCK_FREE(double __attribute__((vector_size(32 * sizeof(double)))));
108+
#endif // __has_attribute(vector_size) && defined(_LIBCPP_VERSION)
107109
CHECK_ALWAYS_LOCK_FREE(struct Empty {});
108110
CHECK_ALWAYS_LOCK_FREE(struct OneInt { int i; });
109111
CHECK_ALWAYS_LOCK_FREE(struct IntArr2 { int i[2]; });

‎libcxx/test/std/utilities/function.objects/func.not_fn/not_fn.pass.cpp

+8-4
Original file line numberDiff line numberDiff line change
@@ -305,15 +305,17 @@ void constructor_tests()
305305
using RetT = decltype(std::not_fn(value));
306306
static_assert(std::is_move_constructible<RetT>::value, "");
307307
static_assert(std::is_copy_constructible<RetT>::value, "");
308-
static_assert(std::is_move_assignable<RetT>::value, "");
309-
static_assert(std::is_copy_assignable<RetT>::value, "");
308+
LIBCPP_STATIC_ASSERT(std::is_move_assignable<RetT>::value, "");
309+
LIBCPP_STATIC_ASSERT(std::is_copy_assignable<RetT>::value, "");
310310
auto ret = std::not_fn(value);
311311
assert(ret() == false);
312312
auto ret2 = std::not_fn(value2);
313313
assert(ret2() == true);
314+
#if defined(_LIBCPP_VERSION)
314315
ret = ret2;
315316
assert(ret() == true);
316317
assert(ret2() == true);
318+
#endif // _LIBCPP_VERSION
317319
}
318320
{
319321
using T = MoveAssignableWrapper;
@@ -322,14 +324,16 @@ void constructor_tests()
322324
using RetT = decltype(std::not_fn(std::move(value)));
323325
static_assert(std::is_move_constructible<RetT>::value, "");
324326
static_assert(!std::is_copy_constructible<RetT>::value, "");
325-
static_assert(std::is_move_assignable<RetT>::value, "");
327+
LIBCPP_STATIC_ASSERT(std::is_move_assignable<RetT>::value, "");
326328
static_assert(!std::is_copy_assignable<RetT>::value, "");
327329
auto ret = std::not_fn(std::move(value));
328330
assert(ret() == false);
329331
auto ret2 = std::not_fn(std::move(value2));
330332
assert(ret2() == true);
333+
#if defined(_LIBCPP_VERSION)
331334
ret = std::move(ret2);
332335
assert(ret() == true);
336+
#endif // _LIBCPP_VERSION
333337
}
334338
}
335339

@@ -426,7 +430,7 @@ void throws_in_constructor_test()
426430
{
427431
ThrowsOnCopy cp;
428432
try {
429-
std::not_fn(cp);
433+
(void)std::not_fn(cp);
430434
assert(false);
431435
} catch (int const& value) {
432436
assert(value == 42);

‎libcxx/test/support/msvc_stdlib_force_include.hpp

+15
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,13 @@ const AssertionDialogAvoider assertion_dialog_avoider{};
5252
#define _MSVC_HAS_FEATURE_memory_sanitizer 0
5353
#define _MSVC_HAS_FEATURE_thread_sanitizer 0
5454

55+
#define __has_attribute(X) _MSVC_HAS_ATTRIBUTE_ ## X
56+
#define _MSVC_HAS_ATTRIBUTE_vector_size 0
57+
58+
#ifdef _NOEXCEPT_TYPES_SUPPORTED
59+
#define __cpp_noexcept_function_type 201510
60+
#endif // _NOEXCEPT_TYPES_SUPPORTED
61+
5562
// Silence compiler warnings.
5663
#pragma warning(disable: 4180) // qualifier applied to function type has no meaning; ignored
5764
#pragma warning(disable: 4324) // structure was padded due to alignment specifier
@@ -85,4 +92,12 @@ const AssertionDialogAvoider assertion_dialog_avoider{};
8592
#define TEST_STD_VER 14
8693
#endif // _HAS_CXX17
8794

95+
// Simulate library feature-test macros.
96+
#define __cpp_lib_invoke 201411
97+
#define __cpp_lib_void_t 201411
98+
99+
#if _HAS_CXX17
100+
#define __cpp_lib_atomic_is_always_lock_free 201603
101+
#endif // _HAS_CXX17
102+
88103
#endif // SUPPORT_MSVC_STDLIB_FORCE_INCLUDE_HPP

0 commit comments

Comments
 (0)
Please sign in to comment.