From b47a9bc6c40a06aeaec76262e056b8bd1a5203ec Mon Sep 17 00:00:00 2001 From: Michael Park Date: Mon, 19 Jun 2017 08:25:57 +0000 Subject: [PATCH] Add a missing SFINAE condition to the `variant`'s converting constructor. Remarks: This function shall not participate in overload resolution unless `is_same_v, variant>` is false, unless `decay_t` is neither a specialization of `in_place_type_t` nor a specialization of `in_place_index_t`, unless `is_constructible_v` is true, and unless the expression `FUN(std::forward(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 git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@305668 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/variant | 2 ++ .../variant.variant/variant.ctor/T.pass.cpp | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/include/variant b/include/variant index 8711ef6eb..f8d3e28ba 100644 --- a/include/variant +++ b/include/variant @@ -1116,6 +1116,8 @@ public: template < class _Arg, enable_if_t, variant>, int> = 0, + enable_if_t>::value, int> = 0, + enable_if_t>::value, int> = 0, class _Tp = __variant_detail::__best_match_t<_Arg, _Types...>, size_t _Ip = __find_detail::__find_unambiguous_index_sfinae<_Tp, _Types...>::value, diff --git a/test/std/utilities/variant/variant.variant/variant.ctor/T.pass.cpp b/test/std/utilities/variant/variant.variant/variant.ctor/T.pass.cpp index d33ea0bd3..3f7cd4f0b 100644 --- a/test/std/utilities/variant/variant.variant/variant.ctor/T.pass.cpp +++ b/test/std/utilities/variant/variant.variant/variant.ctor/T.pass.cpp @@ -37,6 +37,9 @@ struct NoThrowT { NoThrowT(int) noexcept(true) {} }; +struct AnyConstructible { template AnyConstructible(T&&) {} }; +struct NoConstructible { NoConstructible() = delete; }; + void test_T_ctor_noexcept() { { using V = std::variant; @@ -62,6 +65,17 @@ void test_T_ctor_sfinae() { static_assert(!std::is_constructible::value, "no matching constructor"); } + { + using V = std::variant; + static_assert( + !std::is_constructible>::value, + "no matching constructor"); + static_assert(!std::is_constructible>::value, + "no matching constructor"); + } + + + #if !defined(TEST_VARIANT_HAS_NO_REFERENCES) { using V = std::variant;