[PATCH] D26007: [libc++] Cleanup non-portable std::any tests

Casey Carter via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 26 12:51:28 PDT 2016


CaseyCarter created this revision.
CaseyCarter added reviewers: EricWF, mclow.lists.
CaseyCarter added a subscriber: cfe-commits.
CaseyCarter set the repository for this revision to rL LLVM.

Cleanup nonportable behavior in tests for `std::any`

Fixes MS issues 63, 64, and 65.

test/std/utilities/any/any.class/any.cons/move.pass.cpp:

- "Moves are always destructive" is not a portable assumption; check with `LIBCPP_ASSERT`.

test/std/utilities/any/any.class/any.cons/value.pass.cpp:
test/libcxx/utilities/any/any.class/any.cons/value.pass.cpp:

- The standard does not forbid initializing `std::any` from any pointer-to-function type. The `DecayTag` test is a libc++ extension (at best); factor it out into a test in the libcxx hierarchy.

test/std/utilities/any/any.class/any.modifiers/swap.pass.cpp:

- Self-swap is not specified to perform no moves; check with `LIBCPP_ASSERT`.


Repository:
  rL LLVM

https://reviews.llvm.org/D26007

Files:
  test/libcxx/utilities/any/any.class/any.cons/value.pass.cpp
  test/std/utilities/any/any.class/any.cons/move.pass.cpp
  test/std/utilities/any/any.class/any.cons/value.pass.cpp
  test/std/utilities/any/any.class/any.modifiers/swap.pass.cpp


Index: test/std/utilities/any/any.class/any.modifiers/swap.pass.cpp
===================================================================
--- test/std/utilities/any/any.class/any.modifiers/swap.pass.cpp
+++ test/std/utilities/any/any.class/any.modifiers/swap.pass.cpp
@@ -104,7 +104,7 @@
         assertContains<T>(a, 42);
         assert(T::count == 1);
         assert(T::copied == 0);
-        assert(T::moved == 0);
+        LIBCPP_ASSERT(T::moved == 0);
     }
     assert(small::count == 0);
     { // large
@@ -113,9 +113,9 @@
         T::reset();
         a.swap(a);
         assertContains<T>(a, 42);
-        assert(T::copied == 0);
-        assert(T::moved == 0);
         assert(T::count == 1);
+        assert(T::copied == 0);
+        LIBCPP_ASSERT(T::moved == 0);
     }
     assert(large::count == 0);
 }
Index: test/std/utilities/any/any.class/any.cons/value.pass.cpp
===================================================================
--- test/std/utilities/any/any.class/any.cons/value.pass.cpp
+++ test/std/utilities/any/any.class/any.cons/value.pass.cpp
@@ -137,10 +137,6 @@
         static_assert(!std::is_constructible<std::any, T>::value, "");
     }
     {
-        using DecayTag = std::decay_t<BadTag>;
-        static_assert(!std::is_constructible<std::any, DecayTag>::value, "");
-    }
-    {
         // Test that the ValueType&& constructor SFINAE's away when the
         // argument is non-copyable
         struct NoCopy {
Index: test/std/utilities/any/any.class/any.cons/move.pass.cpp
===================================================================
--- test/std/utilities/any/any.class/any.cons/move.pass.cpp
+++ test/std/utilities/any/any.class/any.cons/move.pass.cpp
@@ -80,8 +80,8 @@
         assert(Type::moved == 1 || Type::moved == 2); // zero or more move operations can be performed.
         assert(Type::copied == 0); // no copies can be performed.
         assert(Type::count == 1 + a.has_value());
-        assertEmpty(a); // Moves are always destructive.
         assertContains<Type>(a2, 42);
+        LIBCPP_ASSERT(!a.has_value()); // Moves are always destructive.
         if (a.has_value())
             assertContains<Type>(a, 0);
     }
Index: test/libcxx/utilities/any/any.class/any.cons/value.pass.cpp
===================================================================
--- /dev/null
+++ test/libcxx/utilities/any/any.class/any.cons/value.pass.cpp
@@ -0,0 +1,37 @@
+//===----------------------------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++98, c++03, c++11, c++14
+
+// <any>
+
+// template <class Value> any(Value &&)
+
+// Test construction from a value.
+// Concerns:
+// ---------
+// 1. The value is properly move/copied depending on the value category.
+// 2. Both small and large values are properly handled.
+
+
+#include <any>
+#include <type_traits>
+
+#include "test_macros.h"
+
+using std::any;
+using std::any_cast;
+
+int main() {
+    // Test that any(ValueType&&) is *never* selected for a std::in_place type.
+    // Test that the tag type is properly handled in SFINAE
+    using BadTag = std::in_place_type_t<int>;
+    using DecayTag = std::decay_t<BadTag>;
+    static_assert(!std::is_constructible<std::any, DecayTag>::value, "");
+}


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D26007.75934.patch
Type: text/x-patch
Size: 3526 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20161026/e802d95e/attachment-0001.bin>


More information about the cfe-commits mailing list