From f586dc88484fea8ad790218c9f02489aa936015b Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Fri, 12 Mar 2021 20:15:09 +0200 Subject: [PATCH 1/2] Add test for inherited constructors (refs #26) --- test/Jamfile | 2 ++ test/variant_derived_construct.cpp | 33 ++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 test/variant_derived_construct.cpp diff --git a/test/Jamfile b/test/Jamfile index 682b862..d104a1b 100644 --- a/test/Jamfile +++ b/test/Jamfile @@ -119,3 +119,5 @@ run variant_visit_r.cpp : : : gcc,windows:release gcc,cygwin:release ; + +compile variant_derived_construct.cpp ; diff --git a/test/variant_derived_construct.cpp b/test/variant_derived_construct.cpp new file mode 100644 index 0000000..6844336 --- /dev/null +++ b/test/variant_derived_construct.cpp @@ -0,0 +1,33 @@ +// Copyright 2021 Peter Dimov. +// Distributed under the Boost Software License, Version 1.0. +// https://www.boost.org/LICENSE_1_0.txt + +#include + +using namespace boost::variant2; + +template class X: variant +{ + using base = variant; + using base::base; +}; + +struct Y +{ + Y( Y const& rhs ) = default; + + template Y( T const& t ) + { + t.bar(); + } +}; + +int main() +{ + using W = X; + + W a( 1 ); + W b( a ); + + (void)b; +} From 90cda5339f8bea7d9bd0fc391ec4b9f4ae2a582f Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Fri, 12 Mar 2021 23:40:14 +0200 Subject: [PATCH 2/2] Disable U&& constructor for derived types --- include/boost/variant2/variant.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/boost/variant2/variant.hpp b/include/boost/variant2/variant.hpp index 06a0419..9609335 100644 --- a/include/boost/variant2/variant.hpp +++ b/include/boost/variant2/variant.hpp @@ -1581,7 +1581,7 @@ public: template::type, - class E1 = typename std::enable_if< !std::is_same::value && !detail::is_in_place_index::value && !detail::is_in_place_type::value >::type, + class E1 = typename std::enable_if< !std::is_same::value && !std::is_base_of::value && !detail::is_in_place_index::value && !detail::is_in_place_type::value >::type, class V = detail::resolve_overload_type, class E2 = typename std::enable_if::value>::type >