]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit - gdb/testsuite/ChangeLog
gdb: rank an lvalue argument incompatible for an rvalue parameter
authorTankut Baris Aktemur <tankut.baris.aktemur@intel.com>
Mon, 9 Dec 2019 16:07:47 +0000 (17:07 +0100)
committerTankut Baris Aktemur <tankut.baris.aktemur@intel.com>
Mon, 9 Dec 2019 17:27:51 +0000 (18:27 +0100)
commit330f1d3825daa0d9e8d6c54f4fcf6fa5800e5664
treeaf9082e08796d7fc0de30d257f67d91a30f6da49
parentb43315e206362a09ae70da71a6631bb5e2770554
gdb: rank an lvalue argument incompatible for an rvalue parameter

Passing an lvalue argument to a function that takes an rvalue parameter
is not allowed per C++ rules.  Consider this function:

    int g (int &&x) { return x; }

Calling g as in

    int i = 5;
    int j = g (i);

is illegal.  For instance, GCC 9.2.1 yields

~~~
test.cpp: In function ‘int main()’:
test.cpp:6:14: error: cannot bind rvalue reference of type ‘int&&’ to
lvalue of type ‘int’
    6 |   int j = g (i);
      |              ^
~~~

GDB currently allows this function call:

~~~
(gdb) print g(i)
$1 = 5
~~~

Fix this by ranking an lvalue argument incompatible with an rvalue
parameter.  The behavior after this patch is:

~~~
(gdb) print g(i)
Cannot resolve function g to any overloaded instance
~~~

Tested with GCC 9.2.1.

gdb/ChangeLog:
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.

gdb/testsuite/ChangeLog:
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.

Change-Id: I4a6dfc7dac63efa1e3b9f8f391e4b736fbdccdc1
gdb/ChangeLog
gdb/gdbtypes.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.cp/rvalue-ref-overload.cc
gdb/testsuite/gdb.cp/rvalue-ref-overload.exp