From b24290fb5bfba313dc7143aa29a7b161fd501997 Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Mon, 11 Apr 2011 18:00:06 -0400 Subject: [PATCH] PR c++/48457, Core 1238 PR c++/48457, Core 1238 * call.c (reference_binding): Allow rvalue reference to bind to function lvalue. * tree.c (lvalue_kind): Functions are always lvalues. From-SVN: r172282 --- gcc/cp/ChangeLog | 7 ++++++ gcc/cp/call.c | 4 +++- gcc/cp/tree.c | 4 +++- gcc/testsuite/ChangeLog | 4 ++++ gcc/testsuite/g++.dg/cpp0x/rv-func.C | 22 +++++++++++++++++++ libstdc++-v3/ChangeLog | 4 ++++ .../testsuite/20_util/is_convertible/value.cc | 2 +- 7 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/rv-func.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 1b8f87363af..10400516965 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,10 @@ +2011-04-11 Jason Merrill + + PR c++/48457, Core 1238 + * call.c (reference_binding): Allow rvalue reference to bind to + function lvalue. + * tree.c (lvalue_kind): Functions are always lvalues. + 2011-04-07 Jason Merrill PR c++/48500 diff --git a/gcc/cp/call.c b/gcc/cp/call.c index 096fbbc3d9c..4d03646b444 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -1521,8 +1521,10 @@ reference_binding (tree rto, tree rfrom, tree expr, bool c_cast_p, int flags) actually occurs. */ conv->need_temporary_p = true; - /* Don't allow binding of lvalues to rvalue references. */ + /* Don't allow binding of lvalues (other than function lvalues) to + rvalue references. */ if (is_lvalue && TYPE_REF_IS_RVALUE (rto) + && TREE_CODE (to) != FUNCTION_TYPE && !(flags & LOOKUP_PREFER_RVALUE)) conv->bad_p = true; diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c index 3594ae42dd5..d6b6197cbe2 100644 --- a/gcc/cp/tree.c +++ b/gcc/cp/tree.c @@ -73,7 +73,9 @@ lvalue_kind (const_tree ref) if (TYPE_REF_IS_RVALUE (TREE_TYPE (ref)) && TREE_CODE (ref) != PARM_DECL && TREE_CODE (ref) != VAR_DECL - && TREE_CODE (ref) != COMPONENT_REF) + && TREE_CODE (ref) != COMPONENT_REF + /* Functions are always lvalues. */ + && TREE_CODE (TREE_TYPE (TREE_TYPE (ref))) != FUNCTION_TYPE) return clk_rvalueref; /* lvalue references and named rvalue references are lvalues. */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index dee6793d931..3812feff89a 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2011-04-11 Jason Merrill + + * g++.dg/cpp0x/rv-func.C: New. + 2011-04-11 Rainer Orth * gcc.dg/torture/pr47917.c: Define _ISO_C_SOURCE=19990L for diff --git a/gcc/testsuite/g++.dg/cpp0x/rv-func.C b/gcc/testsuite/g++.dg/cpp0x/rv-func.C new file mode 100644 index 00000000000..db142961128 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/rv-func.C @@ -0,0 +1,22 @@ +// PR c++/48457, Core 1238 +// { dg-options -std=c++0x } + +template +T&& create(); + +template +void test() { + T t(create()); + (void) t; +} + +void f (void (&)()); +void f (void (&&)()); + +int main() { + test(); + test(); + // This call should choose the lvalue reference overload. + // { dg-final { scan-assembler-not "_Z1fOFvvE" } } + f(create()); +} diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index c4ed61f5376..5768ea60708 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,7 @@ +2011-04-08 Jason Merrill + + * testsuite/20_util/is_convertible/value.cc: Adjust. + 2011-04-11 Paolo Carlini * testsuite/25_algorithms/inplace_merge/moveable.cc: Actually run diff --git a/libstdc++-v3/testsuite/20_util/is_convertible/value.cc b/libstdc++-v3/testsuite/20_util/is_convertible/value.cc index f6282a90196..fc6007ac555 100644 --- a/libstdc++-v3/testsuite/20_util/is_convertible/value.cc +++ b/libstdc++-v3/testsuite/20_util/is_convertible/value.cc @@ -93,7 +93,7 @@ void test01() const volatile int&>(false)) ); VERIFY( (test_relationship(false)) ); - VERIFY( (test_relationship(false)) ); + VERIFY( (test_relationship(true)) ); VERIFY( (test_relationship(false)) ); VERIFY( (test_relationship(false)) ); -- 2.30.2