[libcxx][test] compiler options are non-portable

... it's easier to suppress warnings internally, where we can detect the compiler.

* Rename `TEST_COMPILER_C1XX` to `TEST_COMPILER_MSVC`
* Rename all `TEST_WORKAROUND_C1XX_<meow>` to `TEST_WORKAROUND_MSVC_<meow>`

Differential Revision: https://reviews.llvm.org/D117422
This commit is contained in:
Casey Carter 2021-12-29 15:25:53 -08:00
parent c4f66632da
commit 4e00a1921f
25 changed files with 87 additions and 63 deletions

View File

@ -14,7 +14,7 @@
#error "This header complements the Microsoft C Runtime library, and should not be included otherwise."
#endif
#if defined(__clang__)
#error "This header should only be included when using Microsofts C1XX frontend"
#error "This header should only be included when using Microsoft's C1XX frontend"
#endif
#include <float.h> // limit constants

View File

@ -16,7 +16,7 @@
#include "test_macros.h"
#ifdef TEST_COMPILER_C1XX
#ifdef TEST_COMPILER_MSVC
#pragma warning(disable: 4244) // conversion from 'const double' to 'int', possible loss of data
#endif

View File

@ -165,14 +165,14 @@ void test_ctor_with_different_value_type() {
// Make sure initialization is performed with each element value, not with
// a memory blob.
float array[3] = {0.0f, 1.0f, 2.0f};
#ifdef TEST_COMPILER_C1XX
#ifdef TEST_COMPILER_MSVC
#pragma warning(push)
#pragma warning(disable: 4244) // conversion from 'float' to 'int', possible loss of data
#endif // TEST_COMPILER_C1XX
#endif // TEST_COMPILER_MSVC
std::vector<int> v(array, array + 3);
#ifdef TEST_COMPILER_C1XX
#ifdef TEST_COMPILER_MSVC
#pragma warning(pop)
#endif // TEST_COMPILER_C1XX
#endif // TEST_COMPILER_MSVC
assert(v[0] == 0);
assert(v[1] == 1);
assert(v[2] == 2);

View File

@ -22,7 +22,7 @@
#pragma clang diagnostic ignored "-Wliteral-conversion"
#endif
#ifdef TEST_COMPILER_C1XX
#ifdef TEST_COMPILER_MSVC
#pragma warning(disable: 4244) // conversion from 'X' to 'Y', possible loss of data
#endif

View File

@ -7,19 +7,24 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17, libcpp-no-concepts
// ADDITIONAL_COMPILE_FLAGS: -Wno-sign-compare
// constexpr auto synth-three-way = ...;
// via std::tuple<T>(t) <=> std::tuple<U>(u), which exposes its behavior most directly
#include "test_macros.h"
#if defined(TEST_COMPILER_CLANG) || defined(TEST_COMPILER_GCC)
#pragma GCC diagnostic ignored "-Wsign-compare"
#elif defined(TEST_COMPILER_MSVC)
#pragma warning(disable: 4242 4244) // Various truncation warnings
#endif
#include <cassert>
#include <compare>
#include <limits> // quiet_NaN
#include <tuple>
#include <utility> // declval
#include "test_macros.h"
template <typename T, typename U = T>
concept can_synth_three_way = requires(T t, U u) { std::tuple<T>(t) <=> std::tuple<U>(u); };

View File

@ -22,7 +22,7 @@
#include "test_iterators.h"
#include "test_macros.h"
#ifdef TEST_COMPILER_C1XX
#ifdef TEST_COMPILER_MSVC
#pragma warning(disable: 4146) // unary minus operator applied to unsigned type, result still unsigned
#endif

View File

@ -44,10 +44,10 @@ test1()
assert((LCE::min() == (c == 0u ? 1u: 0u)));
#endif
#ifdef TEST_COMPILER_C1XX
#ifdef TEST_COMPILER_MSVC
#pragma warning(push)
#pragma warning(disable: 4310) // cast truncates constant value
#endif // TEST_COMPILER_C1XX
#endif // TEST_COMPILER_MSVC
#if TEST_STD_VER >= 11
static_assert((LCE::max() == result_type(m - 1u)), "");
@ -55,9 +55,9 @@ test1()
assert((LCE::max() == result_type(m - 1u)));
#endif
#ifdef TEST_COMPILER_C1XX
#ifdef TEST_COMPILER_MSVC
#pragma warning(pop)
#endif // TEST_COMPILER_C1XX
#endif // TEST_COMPILER_MSVC
static_assert((LCE::default_seed == 1), "");
where(LCE::multiplier);

View File

@ -10,14 +10,19 @@
// UNSUPPORTED: libcpp-no-concepts
// UNSUPPORTED: libcpp-has-no-incomplete-ranges
// ADDITIONAL_COMPILE_FLAGS: -Wno-sign-compare
#include "test_macros.h"
#if defined(TEST_COMPILER_CLANG) || defined(TEST_COMPILER_GCC)
#pragma GCC diagnostic ignored "-Wsign-compare"
#elif defined(TEST_COMPILER_MSVC)
#pragma warning(disable: 4018 4389) // various "signed/unsigned mismatch"
#endif
// constexpr iota_view(type_identity_t<W> value, type_identity_t<Bound> bound);
#include <ranges>
#include <cassert>
#include "test_macros.h"
#include "types.h"
constexpr bool test() {
@ -57,4 +62,3 @@ int main(int, char**) {
return 0;
}

View File

@ -10,7 +10,13 @@
// UNSUPPORTED: libcpp-no-concepts
// UNSUPPORTED: libcpp-has-no-incomplete-ranges
// ADDITIONAL_COMPILE_FLAGS: -Wno-sign-compare
#include "test_macros.h"
#if defined(TEST_COMPILER_CLANG) || defined(TEST_COMPILER_GCC)
#pragma GCC diagnostic ignored "-Wsign-compare"
#elif defined(TEST_COMPILER_MSVC)
#pragma warning(disable: 4018 4389) // various "signed/unsigned mismatch"
#endif
// constexpr auto end() const;
// constexpr iterator end() const requires same_as<W, Bound>;
@ -18,7 +24,6 @@
#include <ranges>
#include <cassert>
#include "test_macros.h"
#include "types.h"
template<class T, class U>

View File

@ -10,14 +10,19 @@
// UNSUPPORTED: libcpp-no-concepts
// UNSUPPORTED: libcpp-has-no-incomplete-ranges
// ADDITIONAL_COMPILE_FLAGS: -Wno-sign-compare
// constexpr W operator*() const noexcept(is_nothrow_copy_constructible_v<W>);
#include "test_macros.h"
#if defined(TEST_COMPILER_CLANG) || defined(TEST_COMPILER_GCC)
#pragma GCC diagnostic ignored "-Wsign-compare"
#elif defined(TEST_COMPILER_MSVC)
#pragma warning(disable: 4018) // various "signed/unsigned mismatch"
#endif
#include <ranges>
#include <cassert>
#include "test_macros.h"
#include "../types.h"
struct NotNoexceptCopy {

View File

@ -245,7 +245,7 @@ void throws_in_constructor_test()
ThrowsOnCopy() = default;
bool operator()() const {
assert(false);
#if defined(TEST_COMPILER_C1XX)
#ifdef TEST_COMPILER_MSVC
__assume(0);
#else
__builtin_unreachable();

View File

@ -34,10 +34,10 @@ template <bool> struct InTemplate {};
int main(int, char**)
{
#ifdef __cpp_lib_is_constant_evaluated
#ifdef TEST_COMPILER_C1XX
#ifdef TEST_COMPILER_MSVC
#pragma warning(push)
#pragma warning(disable: 5063) // 'std::is_constant_evaluated' always evaluates to true in manifestly constant-evaluated expressions
#endif // TEST_COMPILER_C1XX
#endif // TEST_COMPILER_MSVC
// Test the signature
{
ASSERT_SAME_TYPE(decltype(std::is_constant_evaluated()), bool);
@ -55,9 +55,9 @@ int main(int, char**)
static int local_static = std::is_constant_evaluated() ? 42 : -1;
assert(local_static == 42);
}
#ifdef TEST_COMPILER_C1XX
#ifdef TEST_COMPILER_MSVC
#pragma warning(pop)
#endif // TEST_COMPILER_C1XX
#endif // TEST_COMPILER_MSVC
#endif // __cpp_lib_is_constant_evaluated
return 0;
}

View File

@ -18,7 +18,7 @@
#include "test_macros.h"
#if defined(TEST_COMPILER_C1XX)
#ifdef TEST_COMPILER_MSVC
#pragma warning(disable: 6294) // Ill-defined for-loop: initial condition does not satisfy test. Loop body not executed.
#endif

View File

@ -15,7 +15,7 @@
#include "test_macros.h"
#if defined(TEST_COMPILER_C1XX)
#ifdef TEST_COMPILER_MSVC
#pragma warning(disable: 6294) // Ill-defined for-loop: initial condition does not satisfy test. Loop body not executed.
#endif

View File

@ -16,7 +16,7 @@
#include "../bitset_test_cases.h"
#include "test_macros.h"
#if defined(TEST_COMPILER_C1XX)
#ifdef TEST_COMPILER_MSVC
#pragma warning(disable: 6294) // Ill-defined for-loop: initial condition does not satisfy test. Loop body not executed.
#endif

View File

@ -15,7 +15,14 @@
// operator<=>(const tuple<TTypes...>& t, const tuple<UTypes...>& u);
// UNSUPPORTED: c++03, c++11, c++14, c++17, libcpp-no-concepts
// ADDITIONAL_COMPILE_FLAGS: -Wno-sign-compare
#include "test_macros.h"
#if defined(TEST_COMPILER_CLANG) || defined(TEST_COMPILER_GCC)
#pragma GCC diagnostic ignored "-Wsign-compare"
#elif defined(TEST_COMPILER_MSVC)
#pragma warning(disable: 4242 4244) // Various truncation warnings
#endif
#include <cassert>
#include <compare>
@ -23,8 +30,6 @@
#include <tuple>
#include <type_traits> // std::is_constant_evaluated
#include "test_macros.h"
// A custom three-way result type
struct CustomEquality {
friend constexpr bool operator==(const CustomEquality&, int) noexcept { return true; }

View File

@ -239,15 +239,15 @@ void test_constexpr_copy_ctor() {
// Make sure we properly propagate triviality, which implies constexpr-ness (see P0602R4).
#if TEST_STD_VER > 17
using V = std::variant<long, void*, const int>;
#ifdef TEST_WORKAROUND_C1XX_BROKEN_IS_TRIVIALLY_COPYABLE
#ifdef TEST_WORKAROUND_MSVC_BROKEN_IS_TRIVIALLY_COPYABLE
static_assert(std::is_trivially_destructible<V>::value, "");
static_assert(std::is_trivially_copy_constructible<V>::value, "");
static_assert(std::is_trivially_move_constructible<V>::value, "");
static_assert(!std::is_copy_assignable<V>::value, "");
static_assert(!std::is_move_assignable<V>::value, "");
#else // TEST_WORKAROUND_C1XX_BROKEN_IS_TRIVIALLY_COPYABLE
#else // TEST_WORKAROUND_MSVC_BROKEN_IS_TRIVIALLY_COPYABLE
static_assert(std::is_trivially_copyable<V>::value, "");
#endif // TEST_WORKAROUND_C1XX_BROKEN_IS_TRIVIALLY_COPYABLE
#endif // TEST_WORKAROUND_MSVC_BROKEN_IS_TRIVIALLY_COPYABLE
static_assert(test_constexpr_copy_ctor_imp<0>(V(42l)), "");
static_assert(test_constexpr_copy_ctor_imp<1>(V(nullptr)), "");
static_assert(test_constexpr_copy_ctor_imp<2>(V(101)), "");

View File

@ -309,15 +309,15 @@ void test_constexpr_move_ctor() {
// Make sure we properly propagate triviality, which implies constexpr-ness (see P0602R4).
#if TEST_STD_VER > 17
using V = std::variant<long, void*, const int>;
#ifdef TEST_WORKAROUND_C1XX_BROKEN_IS_TRIVIALLY_COPYABLE
#ifdef TEST_WORKAROUND_MSVC_BROKEN_IS_TRIVIALLY_COPYABLE
static_assert(std::is_trivially_destructible<V>::value, "");
static_assert(std::is_trivially_copy_constructible<V>::value, "");
static_assert(std::is_trivially_move_constructible<V>::value, "");
static_assert(!std::is_copy_assignable<V>::value, "");
static_assert(!std::is_move_assignable<V>::value, "");
#else // TEST_WORKAROUND_C1XX_BROKEN_IS_TRIVIALLY_COPYABLE
#else // TEST_WORKAROUND_MSVC_BROKEN_IS_TRIVIALLY_COPYABLE
static_assert(std::is_trivially_copyable<V>::value, "");
#endif // TEST_WORKAROUND_C1XX_BROKEN_IS_TRIVIALLY_COPYABLE
#endif // TEST_WORKAROUND_MSVC_BROKEN_IS_TRIVIALLY_COPYABLE
static_assert(std::is_trivially_move_constructible<V>::value, "");
static_assert(test_constexpr_ctor_imp<0>(V(42l)), "");
static_assert(test_constexpr_ctor_imp<1>(V(nullptr)), "");

View File

@ -23,9 +23,9 @@ template <bool, class T>
struct DepType : T {};
struct NullBase {
#ifndef TEST_WORKAROUND_C1XX_BROKEN_ZA_CTOR_CHECK
#ifndef TEST_WORKAROUND_MSVC_BROKEN_ZA_CTOR_CHECK
protected:
#endif // !TEST_WORKAROUND_C1XX_BROKEN_ZA_CTOR_CHECK
#endif // !TEST_WORKAROUND_MSVC_BROKEN_ZA_CTOR_CHECK
NullBase() = default;
NullBase(NullBase const&) = default;
NullBase& operator=(NullBase const&) = default;
@ -92,9 +92,9 @@ struct TestBase {
++assigned; ++value_assigned;
return *this;
}
#ifndef TEST_WORKAROUND_C1XX_BROKEN_ZA_CTOR_CHECK
#ifndef TEST_WORKAROUND_MSVC_BROKEN_ZA_CTOR_CHECK
protected:
#endif // !TEST_WORKAROUND_C1XX_BROKEN_ZA_CTOR_CHECK
#endif // !TEST_WORKAROUND_MSVC_BROKEN_ZA_CTOR_CHECK
~TestBase() {
assert(value != -999); assert(alive > 0);
--alive; ++destroyed; value = -999;
@ -157,9 +157,9 @@ struct ValueBase {
}
//~ValueBase() { assert(value != -999); value = -999; }
int value;
#ifndef TEST_WORKAROUND_C1XX_BROKEN_ZA_CTOR_CHECK
#ifndef TEST_WORKAROUND_MSVC_BROKEN_ZA_CTOR_CHECK
protected:
#endif // !TEST_WORKAROUND_C1XX_BROKEN_ZA_CTOR_CHECK
#endif // !TEST_WORKAROUND_MSVC_BROKEN_ZA_CTOR_CHECK
constexpr static int check_value(int const& val) {
#if TEST_STD_VER < 14
return val == -1 || val == 999 ? (TEST_THROW(42), 0) : val;
@ -212,9 +212,9 @@ struct TrivialValueBase {
template <bool Dummy = true, typename std::enable_if<Dummy && !Explicit, bool>::type = true>
constexpr TrivialValueBase(std::initializer_list<int>& il, int = 0) : value(static_cast<int>(il.size())) {}
int value;
#ifndef TEST_WORKAROUND_C1XX_BROKEN_ZA_CTOR_CHECK
#ifndef TEST_WORKAROUND_MSVC_BROKEN_ZA_CTOR_CHECK
protected:
#endif // !TEST_WORKAROUND_C1XX_BROKEN_ZA_CTOR_CHECK
#endif // !TEST_WORKAROUND_MSVC_BROKEN_ZA_CTOR_CHECK
constexpr TrivialValueBase() noexcept : value(0) {}
};

View File

@ -180,10 +180,10 @@ struct roundtrip_test_base
r2 = from_chars(buf, r.ptr, x, args...);
#ifdef TEST_COMPILER_C1XX
#ifdef TEST_COMPILER_MSVC
#pragma warning(push)
#pragma warning(disable: 4127) // conditional expression is constant
#endif // TEST_COMPILER_C1XX
#endif // TEST_COMPILER_MSVC
if (std::is_signed<T>::value && v < 0 && std::is_unsigned<X>::value)
{
assert(x == 0xc);
@ -196,9 +196,9 @@ struct roundtrip_test_base
assert(r2.ptr == r.ptr);
assert(r2.ec == std::errc::result_out_of_range);
}
#ifdef TEST_COMPILER_C1XX
#ifdef TEST_COMPILER_MSVC
#pragma warning(pop)
#endif // TEST_COMPILER_C1XX
#endif // TEST_COMPILER_MSVC
}
}

View File

@ -347,15 +347,15 @@ public:
const bool MemCounter::disable_checking = false;
#endif
#ifdef _MSC_VER
#ifdef TEST_COMPILER_MSVC
#pragma warning(push)
#pragma warning(disable: 4640) // '%s' construction of local static object is not thread safe (/Zc:threadSafeInit-)
#endif // _MSC_VER
#endif // TEST_COMPILER_MSVC
inline MemCounter* getGlobalMemCounter() {
static MemCounter counter((MemCounter::MemCounterCtorArg_()));
return &counter;
}
#ifdef _MSC_VER
#ifdef TEST_COMPILER_MSVC
#pragma warning(pop)
#endif

View File

@ -8,7 +8,7 @@
// UNSUPPORTED: c++03
// Verify TEST_WORKAROUND_C1XX_BROKEN_IS_TRIVIALLY_COPYABLE.
// Verify TEST_WORKAROUND_MSVC_BROKEN_IS_TRIVIALLY_COPYABLE.
#include <type_traits>
@ -23,7 +23,7 @@ struct S {
};
int main(int, char**) {
#if defined(TEST_WORKAROUND_C1XX_BROKEN_IS_TRIVIALLY_COPYABLE)
#ifdef TEST_WORKAROUND_MSVC_BROKEN_IS_TRIVIALLY_COPYABLE
static_assert(!std::is_trivially_copyable<S>::value, "");
#else
static_assert(std::is_trivially_copyable<S>::value, "");

View File

@ -8,7 +8,7 @@
// UNSUPPORTED: c++03
// Verify TEST_WORKAROUND_C1XX_BROKEN_ZA_CTOR_CHECK.
// Verify TEST_WORKAROUND_MSVC_BROKEN_ZA_CTOR_CHECK.
#include <type_traits>
@ -33,7 +33,7 @@ auto test(int) -> decltype(PushFront(std::declval<T>()), std::true_type{});
auto test(long) -> std::false_type;
int main(int, char**) {
#if defined(TEST_WORKAROUND_C1XX_BROKEN_ZA_CTOR_CHECK)
#ifdef TEST_WORKAROUND_MSVC_BROKEN_ZA_CTOR_CHECK
static_assert(!decltype(test(0))::value, "");
#else
static_assert(decltype(test(0))::value, "");

View File

@ -77,7 +77,7 @@
# define TEST_COMPILER_APPLE_CLANG
# endif
#elif defined(_MSC_VER)
# define TEST_COMPILER_C1XX
# define TEST_COMPILER_MSVC
#elif defined(__GNUC__)
# define TEST_COMPILER_GCC
#endif

View File

@ -16,12 +16,12 @@
# define TEST_WORKAROUND_EDG_EXPLICIT_CONSTEXPR // VSO-424280
#endif
#if defined(TEST_COMPILER_C1XX)
#ifdef TEST_COMPILER_MSVC
# if _MSC_VER < 1927
# define TEST_WORKAROUND_C1XX_BROKEN_IS_TRIVIALLY_COPYABLE // VSO-117743
# define TEST_WORKAROUND_MSVC_BROKEN_IS_TRIVIALLY_COPYABLE // VSO-117743
# endif
# ifndef _MSC_EXTENSIONS
# define TEST_WORKAROUND_C1XX_BROKEN_ZA_CTOR_CHECK // VSO-119998
# define TEST_WORKAROUND_MSVC_BROKEN_ZA_CTOR_CHECK // VSO-119998
# endif
#endif