diff options
-rw-r--r-- | gdb/ChangeLog | 5 | ||||
-rw-r--r-- | gdb/gdbtypes.c | 7 | ||||
-rw-r--r-- | gdb/testsuite/ChangeLog | 7 | ||||
-rw-r--r-- | gdb/testsuite/gdb.cp/rvalue-ref-overload.cc | 12 | ||||
-rw-r--r-- | gdb/testsuite/gdb.cp/rvalue-ref-overload.exp | 4 |
5 files changed, 30 insertions, 5 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 9709d0de335..329080e645c 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,8 @@ +2019-12-09 Tankut Baris Aktemur <tankut.baris.aktemur@intel.com> + + * gdbtypes.c (rank_one_type): Return INCOMPATIBLE_TYPE_BADNESS + when ranking an lvalue argument for an rvalue parameter. + 2019-12-08 Wataru Ashihara <wataash@wataash.com> * darwin-nat.c (darwin_nat_target::create_inferior): Fix diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c index 508628af1f7..0896f7189fd 100644 --- a/gdb/gdbtypes.c +++ b/gdb/gdbtypes.c @@ -4303,12 +4303,9 @@ rank_one_type (struct type *parm, struct type *arg, struct value *value) } else { - /* Lvalues should prefer lvalue overloads. */ + /* It's illegal to pass an lvalue as an rvalue. */ if (TYPE_CODE (parm) == TYPE_CODE_RVALUE_REF) - { - rank.subrank = REFERENCE_CONVERSION_RVALUE; - return sum_ranks (rank, REFERENCE_CONVERSION_BADNESS); - } + return INCOMPATIBLE_TYPE_BADNESS; } } diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index bfd686d0d8f..123344ffd8e 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,10 @@ +2019-12-09 Tankut Baris Aktemur <tankut.baris.aktemur@intel.com> + + * gdb.cp/rvalue-ref-overload.cc (g): New function that takes + an rvalue parameter. + * gdb.cp/rvalue-ref-overload.exp: Test calling it with an lvalue + parameter. + 2019-12-09 Andrew Burgess <andrew.burgess@embecosm.com> * gdb.mi/mi-fortran-modules.exp: Add patterns to skip system diff --git a/gdb/testsuite/gdb.cp/rvalue-ref-overload.cc b/gdb/testsuite/gdb.cp/rvalue-ref-overload.cc index e3111d528bd..30634a9c36c 100644 --- a/gdb/testsuite/gdb.cp/rvalue-ref-overload.cc +++ b/gdb/testsuite/gdb.cp/rvalue-ref-overload.cc @@ -62,6 +62,12 @@ f (int &&x) return 3; } +static int +g (int &&x) +{ + return x; +} + int main () { @@ -78,6 +84,12 @@ main () int test_const // = 3 = foo_rr_instance1.overloadConst (arg); + /* The statement below is illegal: cannot bind rvalue reference of + type 'int&&' to lvalue of type 'int'. + + result = g (i); */ + result = g (5); // this is OK + marker1 (); // marker1-returns-here return result; } diff --git a/gdb/testsuite/gdb.cp/rvalue-ref-overload.exp b/gdb/testsuite/gdb.cp/rvalue-ref-overload.exp index e92e90139a4..cac3d4ba588 100644 --- a/gdb/testsuite/gdb.cp/rvalue-ref-overload.exp +++ b/gdb/testsuite/gdb.cp/rvalue-ref-overload.exp @@ -66,3 +66,7 @@ gdb_test "print f (ci)" "2" "lvalue reference to const overload" setup_kfail "c++/15372" "*-*-*" gdb_test "print f (3)" "3" "rvalue reference overload" + +gdb_test "print g (i)" \ + "Cannot resolve function g to any overloaded instance" \ + "passing lvalue arg to rvalue parameter" |