From 11621ac2bda514e7c9403fe4929c135a1a2fb8dd Mon Sep 17 00:00:00 2001 From: Edward Catmur Date: Mon, 9 Aug 2021 11:28:25 +0100 Subject: [PATCH] Require implicit conversion for hana::is_convertible by static_cast In C++20, static_cast can perform aggregate construction (__cpp_aggregate_paren_init). This breaks the example by allowing construction of Employee from its single direct base Person. Change the maybe_static_cast control expression to require implicit conversion. Since this doesn't allow conversion to cv void, add a to_impl for cv void To. --- include/boost/hana/core/to.hpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/include/boost/hana/core/to.hpp b/include/boost/hana/core/to.hpp index 1b54115162..eeb148d937 100644 --- a/include/boost/hana/core/to.hpp +++ b/include/boost/hana/core/to.hpp @@ -49,8 +49,8 @@ BOOST_HANA_NAMESPACE_BEGIN }; template - struct maybe_static_cast(std::declval()) + struct maybe_static_cast()(std::declval()) )> { template static constexpr To apply(X&& x) @@ -63,6 +63,13 @@ BOOST_HANA_NAMESPACE_BEGIN : convert_detail::maybe_static_cast { }; + template + struct to_impl::value>> { + template + static constexpr X apply(X&&) + { return; } + }; + template struct to_impl : embedding<> { template