[PATCH] D21347: [libcxx] [test] Improve portability of hash tests.

Stephan T. Lavavej via cfe-commits cfe-commits at lists.llvm.org
Tue Jun 14 14:18:10 PDT 2016


STL_MSFT created this revision.
STL_MSFT added reviewers: EricWF, mclow.lists.
STL_MSFT added a subscriber: cfe-commits.

Improve portability of hash tests.

These tests were expecting libcxx's identity-hash behavior, which isn't guaranteed by the Standard and isn't provided by MSVC (we currently use FNV-1a for everything). Marking the asserts as libcxx-specific and avoiding unused variable warnings for MSVC makes the tests portable.

http://reviews.llvm.org/D21347

Files:
  test/std/diagnostics/syserr/syserr.hash/error_code.pass.cpp
  test/std/utilities/template.bitset/bitset.hash/bitset.pass.cpp

Index: test/std/utilities/template.bitset/bitset.hash/bitset.pass.cpp
===================================================================
--- test/std/utilities/template.bitset/bitset.hash/bitset.pass.cpp
+++ test/std/utilities/template.bitset/bitset.hash/bitset.pass.cpp
@@ -16,12 +16,12 @@
 //     size_t operator()(T val) const;
 // };
 
-// Not very portable
-
 #include <bitset>
 #include <cassert>
 #include <type_traits>
 
+#include "test_macros.h"
+
 template <std::size_t N>
 void
 test()
@@ -32,7 +32,9 @@
     static_assert((std::is_same<typename H::result_type, std::size_t>::value), "" );
     H h;
     T bs(static_cast<unsigned long long>(N));
-    assert(h(bs) == N);
+    const std::size_t result = h(bs);
+    LIBCPP_ASSERT(result == N);
+    ((void)result); // Prevent unused warning
 }
 
 int main()
Index: test/std/diagnostics/syserr/syserr.hash/error_code.pass.cpp
===================================================================
--- test/std/diagnostics/syserr/syserr.hash/error_code.pass.cpp
+++ test/std/diagnostics/syserr/syserr.hash/error_code.pass.cpp
@@ -16,12 +16,12 @@
 //     size_t operator()(T val) const;
 // };
 
-// Not very portable
-
 #include <system_error>
 #include <cassert>
 #include <type_traits>
 
+#include "test_macros.h"
+
 void
 test(int i)
 {
@@ -31,7 +31,9 @@
     static_assert((std::is_same<H::result_type, std::size_t>::value), "" );
     H h;
     T ec(i, std::system_category());
-    assert(h(ec) == i);
+    const std::size_t result = h(ec);
+    LIBCPP_ASSERT(result == i);
+    ((void)result); // Prevent unused warning
 }
 
 int main()


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D21347.60751.patch
Type: text/x-patch
Size: 1601 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160614/13f5bc22/attachment.bin>


More information about the cfe-commits mailing list