diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 259b0c717b9..a110efe90c0 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,9 @@ 2020-01-28 Jason Merrill + PR c++/90546 + * call.c (build_user_type_conversion_1): Allow a template conversion + returning an rvalue reference to bind directly to an lvalue. + PR c++/90731 * decl.c (grokdeclarator): Propagate eh spec from typedef. diff --git a/gcc/cp/call.c b/gcc/cp/call.c index 009cb85ad60..fde29f8f631 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -4115,6 +4115,8 @@ build_user_type_conversion_1 (tree totype, tree expr, int flags, EXPR_LOCATION (expr)); } else if (TYPE_REF_P (totype) && !ics->rvaluedness_matches_p + /* Limit this to non-templates for now (PR90546). */ + && !cand->template_decl && TREE_CODE (TREE_TYPE (totype)) != FUNCTION_TYPE) { /* If we are called to convert to a reference type, we are trying diff --git a/gcc/testsuite/g++.dg/cpp0x/rv-conv3.C b/gcc/testsuite/g++.dg/cpp0x/rv-conv3.C new file mode 100644 index 00000000000..5f727fcc0d5 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/rv-conv3.C @@ -0,0 +1,15 @@ +// PR c++/90546 +// { dg-do link { target c++11 } } + +struct Foo { }; +void test(const Foo&) {} +Foo f; +struct Bar { + template operator T&&(); +}; +template<> Bar::operator const Foo&&() { + return static_cast(f); +} +int main() { + test(Bar{}); +}