[libcxx] r305668 - Add a missing SFINAE condition to the `variant`'s converting constructor.

Michael Park via cfe-commits cfe-commits at lists.llvm.org
Mon Jun 19 01:25:57 PDT 2017


Author: mpark
Date: Mon Jun 19 03:25:57 2017
New Revision: 305668

URL: http://llvm.org/viewvc/llvm-project?rev=305668&view=rev
Log:
Add a missing SFINAE condition to the `variant`'s converting constructor.

Remarks: This function shall not participate in overload resolution unless
         `is_same_v<decay_t<T>, variant>` is false, unless `decay_t<T>` is
         neither a specialization of `in_place_type_t` nor a specialization of
         `in_place_index_t`, unless `is_constructible_v<Tj, T>` is true, and
         unless the expression `FUN(std::forward<T>(t))` (with `FUN` being the
         above-mentioned set of imaginary functions) is well formed.

Depends on D34111.

Reviewers: EricWF, K-ballo

Reviewed By: EricWF

Subscribers: fhahn

Differential Revision: https://reviews.llvm.org/D34112

Modified:
    libcxx/trunk/include/variant
    libcxx/trunk/test/std/utilities/variant/variant.variant/variant.ctor/T.pass.cpp

Modified: libcxx/trunk/include/variant
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/variant?rev=305668&r1=305667&r2=305668&view=diff
==============================================================================
--- libcxx/trunk/include/variant (original)
+++ libcxx/trunk/include/variant Mon Jun 19 03:25:57 2017
@@ -1116,6 +1116,8 @@ public:
   template <
       class _Arg,
       enable_if_t<!is_same_v<decay_t<_Arg>, variant>, int> = 0,
+      enable_if_t<!__is_inplace_type<decay_t<_Arg>>::value, int> = 0,
+      enable_if_t<!__is_inplace_index<decay_t<_Arg>>::value, int> = 0,
       class _Tp = __variant_detail::__best_match_t<_Arg, _Types...>,
       size_t _Ip =
           __find_detail::__find_unambiguous_index_sfinae<_Tp, _Types...>::value,

Modified: libcxx/trunk/test/std/utilities/variant/variant.variant/variant.ctor/T.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/variant/variant.variant/variant.ctor/T.pass.cpp?rev=305668&r1=305667&r2=305668&view=diff
==============================================================================
--- libcxx/trunk/test/std/utilities/variant/variant.variant/variant.ctor/T.pass.cpp (original)
+++ libcxx/trunk/test/std/utilities/variant/variant.variant/variant.ctor/T.pass.cpp Mon Jun 19 03:25:57 2017
@@ -37,6 +37,9 @@ struct NoThrowT {
   NoThrowT(int) noexcept(true) {}
 };
 
+struct AnyConstructible { template <typename T> AnyConstructible(T&&) {} };
+struct NoConstructible { NoConstructible() = delete; };
+
 void test_T_ctor_noexcept() {
   {
     using V = std::variant<Dummy, NoThrowT>;
@@ -62,6 +65,17 @@ void test_T_ctor_sfinae() {
     static_assert(!std::is_constructible<V, int>::value,
                   "no matching constructor");
   }
+  {
+    using V = std::variant<AnyConstructible, NoConstructible>;
+    static_assert(
+        !std::is_constructible<V, std::in_place_type_t<NoConstructible>>::value,
+        "no matching constructor");
+    static_assert(!std::is_constructible<V, std::in_place_index_t<1>>::value,
+                  "no matching constructor");
+  }
+
+
+
 #if !defined(TEST_VARIANT_HAS_NO_REFERENCES)
   {
     using V = std::variant<int, int &&>;




More information about the cfe-commits mailing list