+2019-03-11 Jason Merrill <jason@redhat.com>
+
+ PR c++/86521 - wrong overload resolution with ref-qualifiers.
+ * call.c (build_user_type_conversion_1): Don't use a conversion to a
+ reference of the wrong rvalueness for direct binding.
+
2019-03-11 Martin Liska <mliska@suse.cz>
* cvt.c (build_expr_type_conversion): Wrap apostrophes
rettype, totype,
EXPR_LOCATION (expr));
}
+ else if (TYPE_REF_P (totype) && !ics->rvaluedness_matches_p
+ && TREE_CODE (TREE_TYPE (totype)) != FUNCTION_TYPE)
+ {
+ /* If we are called to convert to a reference type, we are trying
+ to find a direct binding per [over.match.ref], so rvaluedness
+ must match for non-functions. */
+ cand->viable = 0;
+ }
else if (DECL_NONCONVERTING_P (cand->fn)
&& ics->rank > cr_exact)
{
--- /dev/null
+// PR c++/86521
+// { dg-do compile { target c++11 } }
+
+template <class T> T&& move (T&);
+
+struct Dest {
+ Dest() = default;
+ Dest( Dest && ) = default;
+ Dest( Dest const & ) = delete;
+};
+
+struct Source {
+ Dest val;
+ operator Dest () && { return move( val ); }
+ operator Dest const & () const & { return val; }
+};
+
+int main() {
+ Source x;
+ Dest d(move(x)); // { dg-error "ambiguous" }
+}
// Binding through reference-compatible type is required to perform
// direct-initialization as described in [over.match.ref] p. 1 b. 1:
static_assert(std::is_constructible<int&, ExplicitTo<int&>>::value, "Error");
-static_assert(std::is_constructible<const int&, ExplicitTo<int&&>>::value,
- "Error");
static_assert(std::is_constructible<int&&, ExplicitTo<int&&>>::value, "Error");
+// But an xvalue doesn't count for direct binding.
+static_assert(!std::is_constructible<const int&, ExplicitTo<int&&>>::value,
+ "Error");
+
// Binding through temporary behaves like copy-initialization,
// see [dcl.init.ref] p. 5, very last sub-bullet:
static_assert(!std::is_constructible<const int&, ExplicitTo<double&&>>::value,