[libcxx] r287391 - [libcxx] [test] D26812: In random tests, use real static_asserts and silence a warning.
Stephan T. Lavavej via cfe-commits
cfe-commits at lists.llvm.org
Fri Nov 18 14:45:33 PST 2016
Author: stl_msft
Date: Fri Nov 18 16:45:32 2016
New Revision: 287391
URL: http://llvm.org/viewvc/llvm-project?rev=287391&view=rev
Log:
[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.
Modified:
libcxx/trunk/test/std/numerics/rand/rand.adapt/rand.adapt.disc/values.pass.cpp
libcxx/trunk/test/std/numerics/rand/rand.adapt/rand.adapt.ibits/values.pass.cpp
libcxx/trunk/test/std/numerics/rand/rand.adapt/rand.adapt.shuf/values.pass.cpp
libcxx/trunk/test/std/numerics/rand/rand.eng/rand.eng.lcong/values.pass.cpp
libcxx/trunk/test/std/numerics/rand/rand.eng/rand.eng.mers/values.pass.cpp
libcxx/trunk/test/std/numerics/rand/rand.eng/rand.eng.sub/values.pass.cpp
Modified: libcxx/trunk/test/std/numerics/rand/rand.adapt/rand.adapt.disc/values.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/numerics/rand/rand.adapt/rand.adapt.disc/values.pass.cpp?rev=287391&r1=287390&r2=287391&view=diff
==============================================================================
--- libcxx/trunk/test/std/numerics/rand/rand.adapt/rand.adapt.disc/values.pass.cpp (original)
+++ libcxx/trunk/test/std/numerics/rand/rand.adapt/rand.adapt.disc/values.pass.cpp Fri Nov 18 16:45:32 2016
@@ -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);
}
Modified: libcxx/trunk/test/std/numerics/rand/rand.adapt/rand.adapt.ibits/values.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/numerics/rand/rand.adapt/rand.adapt.ibits/values.pass.cpp?rev=287391&r1=287390&r2=287391&view=diff
==============================================================================
--- libcxx/trunk/test/std/numerics/rand/rand.adapt/rand.adapt.ibits/values.pass.cpp (original)
+++ libcxx/trunk/test/std/numerics/rand/rand.adapt/rand.adapt.ibits/values.pass.cpp Fri Nov 18 16:45:32 2016
@@ -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()
Modified: libcxx/trunk/test/std/numerics/rand/rand.adapt/rand.adapt.shuf/values.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/numerics/rand/rand.adapt/rand.adapt.shuf/values.pass.cpp?rev=287391&r1=287390&r2=287391&view=diff
==============================================================================
--- libcxx/trunk/test/std/numerics/rand/rand.adapt/rand.adapt.shuf/values.pass.cpp (original)
+++ libcxx/trunk/test/std/numerics/rand/rand.adapt/rand.adapt.shuf/values.pass.cpp Fri Nov 18 16:45:32 2016
@@ -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);
}
Modified: libcxx/trunk/test/std/numerics/rand/rand.eng/rand.eng.lcong/values.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/numerics/rand/rand.eng/rand.eng.lcong/values.pass.cpp?rev=287391&r1=287390&r2=287391&view=diff
==============================================================================
--- libcxx/trunk/test/std/numerics/rand/rand.eng/rand.eng.lcong/values.pass.cpp (original)
+++ libcxx/trunk/test/std/numerics/rand/rand.eng/rand.eng.lcong/values.pass.cpp Fri Nov 18 16:45:32 2016
@@ -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);
Modified: libcxx/trunk/test/std/numerics/rand/rand.eng/rand.eng.mers/values.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/numerics/rand/rand.eng/rand.eng.mers/values.pass.cpp?rev=287391&r1=287390&r2=287391&view=diff
==============================================================================
--- libcxx/trunk/test/std/numerics/rand/rand.eng/rand.eng.mers/values.pass.cpp (original)
+++ libcxx/trunk/test/std/numerics/rand/rand.eng/rand.eng.mers/values.pass.cpp Fri Nov 18 16:45:32 2016
@@ -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);
Modified: libcxx/trunk/test/std/numerics/rand/rand.eng/rand.eng.sub/values.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/numerics/rand/rand.eng/rand.eng.sub/values.pass.cpp?rev=287391&r1=287390&r2=287391&view=diff
==============================================================================
--- libcxx/trunk/test/std/numerics/rand/rand.eng/rand.eng.sub/values.pass.cpp (original)
+++ libcxx/trunk/test/std/numerics/rand/rand.eng/rand.eng.sub/values.pass.cpp Fri Nov 18 16:45:32 2016
@@ -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);
More information about the cfe-commits
mailing list