From: Stephan T. Lavavej Date: Fri, 18 Nov 2016 22:45:32 +0000 (+0000) Subject: [libcxx] [test] D26812: In random tests, use real static_asserts and silence a warning. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ae3c4eec5ab73bf4635939b938eaf4bdbfc6b12b;p=platform%2Fupstream%2Fllvm.git [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. llvm-svn: 287391 --- diff --git a/libcxx/test/std/numerics/rand/rand.adapt/rand.adapt.disc/values.pass.cpp b/libcxx/test/std/numerics/rand/rand.adapt/rand.adapt.disc/values.pass.cpp index 53e4c29..f819f48 100644 --- a/libcxx/test/std/numerics/rand/rand.adapt/rand.adapt.disc/values.pass.cpp +++ b/libcxx/test/std/numerics/rand/rand.adapt/rand.adapt.disc/values.pass.cpp @@ -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); } diff --git a/libcxx/test/std/numerics/rand/rand.adapt/rand.adapt.ibits/values.pass.cpp b/libcxx/test/std/numerics/rand/rand.adapt/rand.adapt.ibits/values.pass.cpp index 20ca7d5..187a71e 100644 --- a/libcxx/test/std/numerics/rand/rand.adapt/rand.adapt.ibits/values.pass.cpp +++ b/libcxx/test/std/numerics/rand/rand.adapt/rand.adapt.ibits/values.pass.cpp @@ -28,16 +28,26 @@ void test1() { typedef std::independent_bits_engine 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 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() diff --git a/libcxx/test/std/numerics/rand/rand.adapt/rand.adapt.shuf/values.pass.cpp b/libcxx/test/std/numerics/rand/rand.adapt/rand.adapt.shuf/values.pass.cpp index eb42d64..be5b4a9 100644 --- a/libcxx/test/std/numerics/rand/rand.adapt/rand.adapt.shuf/values.pass.cpp +++ b/libcxx/test/std/numerics/rand/rand.adapt/rand.adapt.shuf/values.pass.cpp @@ -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); } diff --git a/libcxx/test/std/numerics/rand/rand.eng/rand.eng.lcong/values.pass.cpp b/libcxx/test/std/numerics/rand/rand.eng/rand.eng.lcong/values.pass.cpp index 857a478..7ff4480 100644 --- a/libcxx/test/std/numerics/rand/rand.eng/rand.eng.lcong/values.pass.cpp +++ b/libcxx/test/std/numerics/rand/rand.eng/rand.eng.lcong/values.pass.cpp @@ -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); diff --git a/libcxx/test/std/numerics/rand/rand.eng/rand.eng.mers/values.pass.cpp b/libcxx/test/std/numerics/rand/rand.eng/rand.eng.mers/values.pass.cpp index 331d3c5..3a16d62 100644 --- a/libcxx/test/std/numerics/rand/rand.eng/rand.eng.mers/values.pass.cpp +++ b/libcxx/test/std/numerics/rand/rand.eng/rand.eng.mers/values.pass.cpp @@ -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); diff --git a/libcxx/test/std/numerics/rand/rand.eng/rand.eng.sub/values.pass.cpp b/libcxx/test/std/numerics/rand/rand.eng/rand.eng.sub/values.pass.cpp index 75716a4..b3f12e7 100644 --- a/libcxx/test/std/numerics/rand/rand.eng/rand.eng.sub/values.pass.cpp +++ b/libcxx/test/std/numerics/rand/rand.eng/rand.eng.sub/values.pass.cpp @@ -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);