[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.
64 lines
2.0 KiB
C++
64 lines
2.0 KiB
C++
//===----------------------------------------------------------------------===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// UNSUPPORTED: c++98, c++03, c++11, c++14, c++17
|
|
|
|
// <type_traits>
|
|
|
|
// constexpr bool is_constant_evaluated() noexcept; // C++20
|
|
|
|
#include <type_traits>
|
|
#include <cassert>
|
|
|
|
#include "test_macros.h"
|
|
|
|
#ifndef __cpp_lib_is_constant_evaluated
|
|
#if TEST_HAS_BUILTIN(__builtin_is_constant_evaluated)
|
|
# error __cpp_lib_is_constant_evaluated should be defined
|
|
#endif
|
|
#endif
|
|
|
|
// Disable the tautological constant evaluation warnings for this test,
|
|
// because it's explicitly testing those cases.
|
|
#if TEST_HAS_WARNING("-Wconstant-evaluated") && defined(__clang__)
|
|
#pragma clang diagnostic ignored "-Wconstant-evaluated"
|
|
#endif
|
|
|
|
template <bool> struct InTemplate {};
|
|
|
|
int main(int, char**)
|
|
{
|
|
#ifdef __cpp_lib_is_constant_evaluated
|
|
#ifdef TEST_COMPILER_C1XX
|
|
#pragma warning(push)
|
|
#pragma warning(disable: 5063) // 'std::is_constant_evaluated' always evaluates to true in manifestly constant-evaluated expressions
|
|
#endif // TEST_COMPILER_C1XX
|
|
// Test the signature
|
|
{
|
|
ASSERT_SAME_TYPE(decltype(std::is_constant_evaluated()), bool);
|
|
ASSERT_NOEXCEPT(std::is_constant_evaluated());
|
|
constexpr bool p = std::is_constant_evaluated();
|
|
assert(p);
|
|
}
|
|
// Test the return value of the builtin for basic sanity only. It's the
|
|
// compiler's job to test the builtin for correctness.
|
|
{
|
|
static_assert(std::is_constant_evaluated(), "");
|
|
bool p = std::is_constant_evaluated();
|
|
assert(!p);
|
|
ASSERT_SAME_TYPE(InTemplate<std::is_constant_evaluated()>, InTemplate<true>);
|
|
static int local_static = std::is_constant_evaluated() ? 42 : -1;
|
|
assert(local_static == 42);
|
|
}
|
|
#ifdef TEST_COMPILER_C1XX
|
|
#pragma warning(pop)
|
|
#endif // TEST_COMPILER_C1XX
|
|
#endif // __cpp_lib_is_constant_evaluated
|
|
return 0;
|
|
}
|