diff options
author | Stephan T. Lavavej <stl@microsoft.com> | 2019-12-12 17:16:00 -0800 |
---|---|---|
committer | Stephan T. Lavavej <stl@microsoft.com> | 2019-12-12 18:35:27 -0800 |
commit | bf7dc572f199007cbe042d5ea41bcf873dcedd8f (patch) | |
tree | 741b13a7cf0e218953059bbe96caab0933f38cee /libcxx/test/support | |
parent | bc0c60f714fca54711b806c54467a8ce28c04181 (diff) | |
download | bcm5719-llvm-bf7dc572f199007cbe042d5ea41bcf873dcedd8f.tar.gz bcm5719-llvm-bf7dc572f199007cbe042d5ea41bcf873dcedd8f.zip |
[libcxx] [test] Fix valarray UB and MSVC warnings.
[libcxx] [test] Calling min and max on an empty valarray is UB.
libcxx/test/std/numerics/numarray/template.valarray/valarray.members/min.pass.cpp
libcxx/test/std/numerics/numarray/template.valarray/valarray.members/max.pass.cpp
The calls `v1.min();` and `v1.max();` were emitting nodiscard warnings
with MSVC's STL. Upon closer inspection, these calls were triggering
undefined behavior. N4842 [valarray.members] says:
"T min() const;
8 Preconditions: size() > 0 is true.
T max() const;
10 Preconditions: size() > 0 is true."
As these tests already provide coverage for non-empty valarrays
(immediately above), I've simply deleted the code for empty valarrays.
[libcxx] [test] Add macros to msvc_stdlib_force_include.h (NFC).
libcxx/test/support/msvc_stdlib_force_include.h
These macros are being used by:
libcxx/test/std/utilities/meta/meta.trans/meta.trans.other/result_of11.pass.cpp
Defining them to nothing allows that test to pass.
[libcxx] [test] Silence MSVC warning C5063 for is_constant_evaluated (NFC).
libcxx/test/std/utilities/meta/meta.const.eval/is_constant_evaluated.pass.cpp
This test is intentionally writing code that MSVC intentionally warns
about, so the warning should be silenced.
Additionally, comment an endif for clarity.
[libcxx] [test] Silence MSVC warning C4127 (NFC).
libcxx/test/support/charconv_test_helpers.h
MSVC avoids emitting this warning when it sees a single constexpr value
being tested, but this condition is a mix of compile-time and run-time.
Using push-disable-pop is the least intrusive way to silence this.
[libcxx] [test] Silence MSVC truncation warning (NFC).
libcxx/test/std/containers/sequences/vector/vector.cons/construct_iter_iter.pass.cpp
This test is intentionally truncating float to int, which MSVC
intentionally warns about, so push-disable-pop is necessary.
[libcxx] [test] Avoid truncation warnings in erase_if tests (NFC).
libcxx/test/std/containers/associative/map/map.erasure/erase_if.pass.cpp
libcxx/test/std/containers/associative/multimap/multimap.erasure/erase_if.pass.cpp
libcxx/test/std/containers/unord/unord.map/erase_if.pass.cpp
libcxx/test/std/containers/unord/unord.multimap/erase_if.pass.cpp
These tests use maps with `short` keys and values, emitting MSVC
truncation warnings from `int`. Adding `static_cast` to `key_type`
and `mapped_type` avoids these warnings.
As these tests require C++20 mode (or newer), for brevity I've changed
the multimap tests to use emplace to initialize the test data.
This has no effect on the erase_if testing.
Diffstat (limited to 'libcxx/test/support')
-rw-r--r-- | libcxx/test/support/charconv_test_helpers.h | 7 | ||||
-rw-r--r-- | libcxx/test/support/msvc_stdlib_force_include.h | 2 |
2 files changed, 9 insertions, 0 deletions
diff --git a/libcxx/test/support/charconv_test_helpers.h b/libcxx/test/support/charconv_test_helpers.h index f30956e9a73..4ef4288a34f 100644 --- a/libcxx/test/support/charconv_test_helpers.h +++ b/libcxx/test/support/charconv_test_helpers.h @@ -174,6 +174,10 @@ struct roundtrip_test_base r2 = from_chars(buf, r.ptr, x, args...); +#ifdef TEST_COMPILER_C1XX + #pragma warning(push) + #pragma warning(disable: 4127) // conditional expression is constant +#endif // TEST_COMPILER_C1XX if (std::is_signed<T>::value && v < 0 && std::is_unsigned<X>::value) { assert(x == 0xc); @@ -186,6 +190,9 @@ struct roundtrip_test_base assert(r2.ptr == r.ptr); assert(r2.ec == std::errc::result_out_of_range); } +#ifdef TEST_COMPILER_C1XX + #pragma warning(pop) +#endif // TEST_COMPILER_C1XX } } diff --git a/libcxx/test/support/msvc_stdlib_force_include.h b/libcxx/test/support/msvc_stdlib_force_include.h index 2ec74e85a2a..e3352e52043 100644 --- a/libcxx/test/support/msvc_stdlib_force_include.h +++ b/libcxx/test/support/msvc_stdlib_force_include.h @@ -88,5 +88,7 @@ const AssertionDialogAvoider assertion_dialog_avoider{}; #endif #define _LIBCPP_AVAILABILITY_THROW_BAD_ANY_CAST +#define _LIBCPP_SUPPRESS_DEPRECATED_PUSH +#define _LIBCPP_SUPPRESS_DEPRECATED_POP #endif // SUPPORT_MSVC_STDLIB_FORCE_INCLUDE_H |