[libcxx] [test] D26812: In random tests, use real static_asserts and silence a warning.

In C++11 mode and newer, use real static_asserts.
In C++03 mode, min() and max() aren't constexpr, so use plain asserts.

One test triggers MSVC's warning C4310 "cast truncates constant value".
The code is valid, and yet the warning is valid, so I'm silencing it
through push-disable-pop.

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@287391 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Stephan T. Lavavej
2016-11-18 22:45:32 +00:00
parent c044b03d26
commit 2917004aed
6 changed files with 84 additions and 20 deletions

View File

@@ -35,8 +35,13 @@ test1()
typedef std::ranlux24 E;
static_assert((E::block_size == 223), "");
static_assert((E::used_block == 23), "");
/*static_*/assert((E::min() == 0)/*, ""*/);
/*static_*/assert((E::max() == 0xFFFFFF)/*, ""*/);
#if TEST_STD_VER >= 11
static_assert((E::min() == 0), "");
static_assert((E::max() == 0xFFFFFF), "");
#else
assert((E::min() == 0));
assert((E::max() == 0xFFFFFF));
#endif
where(E::block_size);
where(E::used_block);
}
@@ -47,8 +52,13 @@ test2()
typedef std::ranlux48 E;
static_assert((E::block_size == 389), "");
static_assert((E::used_block == 11), "");
/*static_*/assert((E::min() == 0)/*, ""*/);
/*static_*/assert((E::max() == 0xFFFFFFFFFFFFull)/*, ""*/);
#if TEST_STD_VER >= 11
static_assert((E::min() == 0), "");
static_assert((E::max() == 0xFFFFFFFFFFFFull), "");
#else
assert((E::min() == 0));
assert((E::max() == 0xFFFFFFFFFFFFull));
#endif
where(E::block_size);
where(E::used_block);
}

View File

@@ -28,16 +28,26 @@ void
test1()
{
typedef std::independent_bits_engine<std::ranlux24, 32, unsigned> E;
/*static_*/assert((E::min() == 0)/*, ""*/);
/*static_*/assert((E::max() == 0xFFFFFFFF)/*, ""*/);
#if TEST_STD_VER >= 11
static_assert((E::min() == 0), "");
static_assert((E::max() == 0xFFFFFFFF), "");
#else
assert((E::min() == 0));
assert((E::max() == 0xFFFFFFFF));
#endif
}
void
test2()
{
typedef std::independent_bits_engine<std::ranlux48, 64, unsigned long long> E;
/*static_*/assert((E::min() == 0)/*, ""*/);
/*static_*/assert((E::max() == 0xFFFFFFFFFFFFFFFFull)/*, ""*/);
#if TEST_STD_VER >= 11
static_assert((E::min() == 0), "");
static_assert((E::max() == 0xFFFFFFFFFFFFFFFFull), "");
#else
assert((E::min() == 0));
assert((E::max() == 0xFFFFFFFFFFFFFFFFull));
#endif
}
int main()

View File

@@ -33,8 +33,13 @@ test1()
{
typedef std::knuth_b E;
static_assert(E::table_size == 256, "");
/*static_*/assert((E::min() == 1)/*, ""*/);
/*static_*/assert((E::max() == 2147483646)/*, ""*/);
#if TEST_STD_VER >= 11
static_assert((E::min() == 1), "");
static_assert((E::max() == 2147483646), "");
#else
assert((E::min() == 1));
assert((E::max() == 2147483646));
#endif
where(E::table_size);
}

View File

@@ -37,8 +37,27 @@ test1()
static_assert((LCE::multiplier == a), "");
static_assert((LCE::increment == c), "");
static_assert((LCE::modulus == m), "");
/*static_*/assert((LCE::min() == (c == 0u ? 1u: 0u))/*, ""*/);
/*static_*/assert((LCE::max() == result_type(m - 1u))/*, ""*/);
#if TEST_STD_VER >= 11
static_assert((LCE::min() == (c == 0u ? 1u: 0u)), "");
#else
assert((LCE::min() == (c == 0u ? 1u: 0u)));
#endif
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable: 4310) // cast truncates constant value
#endif // _MSC_VER
#if TEST_STD_VER >= 11
static_assert((LCE::max() == result_type(m - 1u)), "");
#else
assert((LCE::max() == result_type(m - 1u)));
#endif
#ifdef _MSC_VER
#pragma warning(pop)
#endif // _MSC_VER
static_assert((LCE::default_seed == 1), "");
where(LCE::multiplier);
where(LCE::increment);

View File

@@ -60,8 +60,13 @@ test1()
static_assert((E::tempering_c == 0xefc60000), "");
static_assert((E::tempering_l == 18), "");
static_assert((E::initialization_multiplier == 1812433253), "");
/*static_*/assert((E::min() == 0)/*, ""*/);
/*static_*/assert((E::max() == 0xFFFFFFFF)/*, ""*/);
#if TEST_STD_VER >= 11
static_assert((E::min() == 0), "");
static_assert((E::max() == 0xFFFFFFFF), "");
#else
assert((E::min() == 0));
assert((E::max() == 0xFFFFFFFF));
#endif
static_assert((E::default_seed == 5489u), "");
where(E::word_size);
where(E::state_size);
@@ -96,8 +101,13 @@ test2()
static_assert((E::tempering_c == 0xfff7eee000000000ull), "");
static_assert((E::tempering_l == 43), "");
static_assert((E::initialization_multiplier == 6364136223846793005ull), "");
/*static_*/assert((E::min() == 0)/*, ""*/);
/*static_*/assert((E::max() == 0xFFFFFFFFFFFFFFFFull)/*, ""*/);
#if TEST_STD_VER >= 11
static_assert((E::min() == 0), "");
static_assert((E::max() == 0xFFFFFFFFFFFFFFFFull), "");
#else
assert((E::min() == 0));
assert((E::max() == 0xFFFFFFFFFFFFFFFFull));
#endif
static_assert((E::default_seed == 5489u), "");
where(E::word_size);
where(E::state_size);

View File

@@ -38,8 +38,13 @@ test1()
static_assert((E::word_size == 24), "");
static_assert((E::short_lag == 10), "");
static_assert((E::long_lag == 24), "");
/*static_*/assert((E::min() == 0)/*, ""*/);
/*static_*/assert((E::max() == 0xFFFFFF)/*, ""*/);
#if TEST_STD_VER >= 11
static_assert((E::min() == 0), "");
static_assert((E::max() == 0xFFFFFF), "");
#else
assert((E::min() == 0));
assert((E::max() == 0xFFFFFF));
#endif
static_assert((E::default_seed == 19780503u), "");
where(E::word_size);
where(E::short_lag);
@@ -54,8 +59,13 @@ test2()
static_assert((E::word_size == 48), "");
static_assert((E::short_lag == 5), "");
static_assert((E::long_lag == 12), "");
/*static_*/assert((E::min() == 0)/*, ""*/);
/*static_*/assert((E::max() == 0xFFFFFFFFFFFFull)/*, ""*/);
#if TEST_STD_VER >= 11
static_assert((E::min() == 0), "");
static_assert((E::max() == 0xFFFFFFFFFFFFull), "");
#else
assert((E::min() == 0));
assert((E::max() == 0xFFFFFFFFFFFFull));
#endif
static_assert((E::default_seed == 19780503u), "");
where(E::word_size);
where(E::short_lag);