return convert_from_reference (stub);
}
+/* Build a std::declval<TYPE>() expression and return it. */
+
+tree
+build_trait_object (tree type)
+{
+ /* TYPE can't be a function with cv-/ref-qualifiers: std::declval is
+ defined as
+
+ template<class T>
+ typename std::add_rvalue_reference<T>::type declval() noexcept;
+
+ and std::add_rvalue_reference yields T when T is a function with
+ cv- or ref-qualifiers, making the definition ill-formed. */
+ if (FUNC_OR_METHOD_TYPE_P (type)
+ && (type_memfn_quals (type) != TYPE_UNQUALIFIED
+ || type_memfn_rqual (type) != REF_QUAL_NONE))
+ return error_mark_node;
+
+ return build_stub_object (type);
+}
+
/* Determine which function will be called when looking up NAME in TYPE,
called with a single ARGTYPE argument, or no argument if ARGTYPE is
null. FLAGS and COMPLAIN are as for build_new_method_call.
assignable_expr (tree to, tree from)
{
cp_unevaluated cp_uneval_guard;
- to = build_stub_object (to);
- from = build_stub_object (from);
+ to = build_trait_object (to);
+ from = build_trait_object (from);
tree r = cp_build_modify_expr (input_location, to, NOP_EXPR, from, tf_none);
return r;
}
return false;
/* We don't check is_constructible<T, U>: if T isn't constructible
from U, we won't be able to create a conversion. */
- tree val = build_stub_object (from);
+ tree val = build_trait_object (from);
+ if (val == error_mark_node)
+ return false;
if (!TYPE_REF_P (from) && TREE_CODE (from) != FUNCTION_TYPE)
val = CLASS_TYPE_P (from) ? force_rvalue (val, tf_none) : rvalue (val);
return ref_conv_binds_to_temporary (to, val, direct_init_p).is_true ();
if (VOID_TYPE_P (from) && VOID_TYPE_P (to))
return integer_one_node;
cp_unevaluated u;
- tree expr = build_stub_object (from);
+ tree expr = build_trait_object (from);
+ /* std::is_{,nothrow_}convertible test whether the imaginary function
+ definition
+
+ To test() { return std::declval<From>(); }
+
+ is well-formed. A function can't return a function. */
+ if (FUNC_OR_METHOD_TYPE_P (to) || expr == error_mark_node)
+ return error_mark_node;
deferring_access_check_sentinel acs (dk_no_deferred);
return perform_implicit_conversion (to, expr, tf_none);
}
--- /dev/null
+// PR c++/109680
+// { dg-do compile { target c++11 } }
+
+#define SA(X) static_assert((X),#X)
+
+SA(!__is_convertible(int () const, int (*)()));
+SA(!__is_convertible(int (*)(), int () const));
+
+SA( __is_convertible(int (), int (*)()));
+SA(!__is_convertible(int (*)(), int ()));
+
+SA( __is_convertible(int (int), int (*) (int)));
+SA(!__is_convertible(int (*) (int), int (int)));
+
+SA(!__is_convertible(int (int) const, int (*) (int)));
+SA(!__is_convertible(int (*) (int), int (int) const));