return ref_conv_binds_directly (to, val, direct_init_p).is_false ();
}
+/* Worker for is_{,nothrow_}convertible. Attempt to perform an implicit
+ conversion from FROM to TO and return the result. */
+
+static tree
+is_convertible_helper (tree from, tree to)
+{
+ if (VOID_TYPE_P (from) && VOID_TYPE_P (to))
+ return integer_one_node;
+ cp_unevaluated u;
+ tree expr = build_stub_object (from);
+ return perform_implicit_conversion (to, expr, tf_none);
+}
+
/* Return true if FROM can be converted to TO using implicit conversions,
or both FROM and TO are possibly cv-qualified void. NB: This doesn't
implement the "Access checks are performed as if from a context unrelated
bool
is_convertible (tree from, tree to)
{
- if (VOID_TYPE_P (from) && VOID_TYPE_P (to))
- return true;
- tree expr = build_stub_object (from);
- expr = perform_implicit_conversion (to, expr, tf_none);
+ tree expr = is_convertible_helper (from, to);
if (expr == error_mark_node)
return false;
return !!expr;
bool
is_nothrow_convertible (tree from, tree to)
{
- if (VOID_TYPE_P (from) && VOID_TYPE_P (to))
- return true;
- tree expr = build_stub_object (from);
- expr = perform_implicit_conversion (to, expr, tf_none);
+ tree expr = is_convertible_helper (from, to);
if (expr == NULL_TREE || expr == error_mark_node)
return false;
return expr_noexcept_p (expr, tf_none);
--- /dev/null
+// PR c++/106784
+// { dg-do compile { target c++11 } }
+// Make sure we don't reject this at runtime by trying to instantiate
+// something that would be ill-formed.
+
+struct A;
+struct B { template<class T> B(const T&) noexcept { T::nonexistent; } };
+
+static_assert(__is_convertible(const A&, B), "");
--- /dev/null
+// PR c++/106784
+// { dg-do compile { target c++11 } }
+// Make sure we don't reject this at runtime by trying to instantiate
+// something that would be ill-formed.
+
+struct A;
+struct B { template<class T> B(const T&) noexcept { T::nonexistent; } };
+
+static_assert(__is_nothrow_convertible(const A&, B), "");