[PATCH] D21878: [libcxx] [test] Make futures.overview/future_errc.pass.cpp and launch.pass.cpp more portable.

Stephan T. Lavavej via cfe-commits cfe-commits at lists.llvm.org
Wed Jun 29 16:44:06 PDT 2016


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

Make futures.overview/future_errc.pass.cpp and launch.pass.cpp more portable.

future_errc.pass.cpp was assuming specific values, which aren't guaranteed by the Standard, and MSVC uses different ones. Update the comment, and rewrite the tests to verify the Standard's guarantees of distinctness and nonzeroness.

launch.pass.cpp also contains non-Standard assumptions. They happen to be true for MSVC, with the exception of a static_assert about bitwise NOT. Apparently for libcxx, this operator modifies only 2 bits. For MSVC, it modifies all the bits in the representation. Mark this static_assert as libcxx-specific.

http://reviews.llvm.org/D21878

Files:
  test/std/thread/futures/futures.overview/future_errc.pass.cpp
  test/std/thread/futures/futures.overview/launch.pass.cpp

Index: test/std/thread/futures/futures.overview/launch.pass.cpp
===================================================================
--- test/std/thread/futures/futures.overview/launch.pass.cpp
+++ test/std/thread/futures/futures.overview/launch.pass.cpp
@@ -32,7 +32,7 @@
     LIBCPP_STATIC_ASSERT(std::launch::any == (std::launch::async | std::launch::deferred), "");
     static_assert(std::launch(0) == (std::launch::async & std::launch::deferred), "");
     LIBCPP_STATIC_ASSERT(std::launch::any == (std::launch::async ^ std::launch::deferred), "");
-    static_assert(std::launch::deferred == ~std::launch::async, "");
+    LIBCPP_STATIC_ASSERT(std::launch::deferred == ~std::launch::async, "");
     std::launch x = std::launch::async;
     x &= std::launch::deferred;
     assert(x == std::launch(0));
Index: test/std/thread/futures/futures.overview/future_errc.pass.cpp
===================================================================
--- test/std/thread/futures/futures.overview/future_errc.pass.cpp
+++ test/std/thread/futures/futures.overview/future_errc.pass.cpp
@@ -13,18 +13,25 @@
 
 // enum class future_errc
 // {
-//     future_already_retrieved = 1,
-//     promise_already_satisfied,
-//     no_state
-//     broken_promise,
+//     broken_promise = implementation-defined,
+//     future_already_retrieved = implementation-defined,
+//     promise_already_satisfied = implementation-defined,
+//     no_state = implementation-defined
 // };
 
 #include <future>
 
 int main()
 {
-    static_assert(static_cast<int>(std::future_errc::future_already_retrieved) == 1, "");
-    static_assert(static_cast<int>(std::future_errc::promise_already_satisfied) == 2, "");
-    static_assert(static_cast<int>(std::future_errc::no_state) == 3, "");
-    static_assert(static_cast<int>(std::future_errc::broken_promise) == 4, "");
+    static_assert(std::future_errc::broken_promise != std::future_errc::future_already_retrieved, "");
+    static_assert(std::future_errc::broken_promise != std::future_errc::promise_already_satisfied, "");
+    static_assert(std::future_errc::broken_promise != std::future_errc::no_state, "");
+    static_assert(std::future_errc::future_already_retrieved != std::future_errc::promise_already_satisfied, "");
+    static_assert(std::future_errc::future_already_retrieved != std::future_errc::no_state, "");
+    static_assert(std::future_errc::promise_already_satisfied != std::future_errc::no_state, "");
+
+    static_assert(std::future_errc::broken_promise != static_cast<std::future_errc>(0), "");
+    static_assert(std::future_errc::future_already_retrieved != static_cast<std::future_errc>(0), "");
+    static_assert(std::future_errc::promise_already_satisfied != static_cast<std::future_errc>(0), "");
+    static_assert(std::future_errc::no_state != static_cast<std::future_errc>(0), "");
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D21878.62311.patch
Type: text/x-patch
Size: 2846 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160629/d4226187/attachment.bin>


More information about the cfe-commits mailing list