aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gdb/ChangeLog7
-rw-r--r--gdb/NEWS3
-rw-r--r--gdb/doc/gdb.texinfo6
-rw-r--r--gdb/testsuite/ChangeLog18
-rw-r--r--gdb/testsuite/gdb.cp/demangle.exp42
-rw-r--r--gdb/testsuite/gdb.cp/rvalue-ref-casts.cc75
-rw-r--r--gdb/testsuite/gdb.cp/rvalue-ref-casts.exp77
-rw-r--r--gdb/testsuite/gdb.cp/rvalue-ref-overload.cc86
-rw-r--r--gdb/testsuite/gdb.cp/rvalue-ref-overload.exp69
-rw-r--r--gdb/testsuite/gdb.cp/rvalue-ref-params.cc83
-rw-r--r--gdb/testsuite/gdb.cp/rvalue-ref-params.exp69
-rw-r--r--gdb/testsuite/gdb.cp/rvalue-ref-sizeof.cc75
-rw-r--r--gdb/testsuite/gdb.cp/rvalue-ref-sizeof.exp43
-rw-r--r--gdb/testsuite/gdb.cp/rvalue-ref-types.cc79
-rw-r--r--gdb/testsuite/gdb.cp/rvalue-ref-types.exp128
-rw-r--r--gdb/testsuite/gdb.python/py-rvalue-ref-value-cc.cc59
-rw-r--r--gdb/testsuite/gdb.python/py-rvalue-ref-value-cc.exp57
17 files changed, 972 insertions, 4 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 2f44494..87d3859 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,6 +1,13 @@
2017-03-20 Artemiy Volkov <artemiyv@acm.org>
PR gdb/14441
+ * NEWS: Mention support for rvalue references in GDB and python.
+ * doc/gdb.texinfo (C Plus Plus Expressions): Mention that GDB
+ supports both lvalue and rvalue references.
+
+2017-03-20 Artemiy Volkov <artemiyv@acm.org>
+
+ PR gdb/14441
* gdbtypes.c (rank_one_type): Implement overloading
resolution rules regarding rvalue references.
diff --git a/gdb/NEWS b/gdb/NEWS
index b5c68c5..87f528a 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -7,9 +7,12 @@
added by the Memory Protection Keys for Userspace feature which will be
available in future Intel CPUs.
+* GDB now supports C++11 rvalue references.
+
* Python Scripting
** New functions to start, stop and access a running btrace recording.
+ ** Rvalue references are now supported in gdb.Type.
* GDB now supports recording and replaying rdrand and rdseed Intel 64
instructions.
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index c1dfdeb..90785dc 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -14827,9 +14827,9 @@ see @ref{Completion, ,Command Completion}.
@cindex reference declarations
@item
-@value{GDBN} understands variables declared as C@t{++} references; you can use
-them in expressions just as you do in C@t{++} source---they are automatically
-dereferenced.
+@value{GDBN} understands variables declared as C@t{++} lvalue or rvalue
+references; you can use them in expressions just as you do in C@t{++}
+source---they are automatically dereferenced.
In the parameter list shown when @value{GDBN} displays a frame, the values of
reference variables are not displayed (unlike other variables); this
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index edd3a39..2853d8a 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,21 @@
+2017-03-20 Artemiy Volkov <artemiyv@acm.org>
+ Keith Seitz <keiths@redhat.com>
+
+ PR gdb/14441
+ * gdb.cp/demangle.exp: Add rvalue reference tests.
+ * gdb.cp/rvalue-ref-casts.cc: New file.
+ * gdb.cp/rvalue-ref-casts.exp: New file.
+ * gdb.cp/rvalue-ref-overload.cc: New file.
+ * gdb.cp/rvalue-ref-overload.exp: New file.
+ * gdb.cp/rvalue-ref-params.cc: New file.
+ * gdb.cp/rvalue-ref-params.exp: New file.
+ * gdb.cp/rvalue-ref-sizeof.cc: New file.
+ * gdb.cp/rvalue-ref-sizeof.exp: New file.
+ * gdb.cp/rvalue-ref-types.cc: New file.
+ * gdb.cp/rvalue-ref-types.exp: New file.
+ * gdb.python/py-rvalue-ref-value-cc.cc: New file.
+ * gdb.python/py-rvalue-ref-value-cc.exp: New file.
+
2017-03-20 Marc-Andre Laperle <marc-andre.laperle@ericsson.com>
* gdb.mi/mi-solib.exp (test_file_list_shared_libraries):
diff --git a/gdb/testsuite/gdb.cp/demangle.exp b/gdb/testsuite/gdb.cp/demangle.exp
index 0ecf95d..fe51c55 100644
--- a/gdb/testsuite/gdb.cp/demangle.exp
+++ b/gdb/testsuite/gdb.cp/demangle.exp
@@ -70,7 +70,9 @@ proc test_demangling_core {tester test result} {
}
if {[string compare $style $current_demangling_style]} {
- set_demangling_style $style
+ with_test_prefix $test {
+ set_demangling_style $style
+ }
}
$tester "demangle $name" $result $test
@@ -521,6 +523,44 @@ proc test_gnu_style_demangling {} {
test_demangling_exact "gnu: foo__I_200_" "foo(int512_t)"
test_demangling_exact "gnu: foo__I_200" "Can't demangle \"foo__I_200\""
+ # Rvalue reference tests
+ test_demangling_exact "gnu-v3: _ZN9ArrowLine19ArrowheadIntersectsEP9ArrowheadO6BoxObjP7Graphic" "ArrowLine::ArrowheadIntersects(Arrowhead*, BoxObj&&, Graphic*)"
+ test_demangling "gnu-v3: _Z13BitPatterntoaOK10BitPatternccc" \
+ "BitPatterntoa\[(\]+(const BitPattern|BitPattern const)&&, char, char, char\[)\]+"
+ test_demangling_exact "gnu-v3: _ZN8TextCode14CoreConstDeclsEO7ostream" "TextCode::CoreConstDecls(ostream&&)"
+ test_demangling "gnu-v3: _Z31DrawDestinationTransformedImageP7_XImageiiS0_iimjiijmmP4_XGCOK13ivTransformeriiii" \
+ "DrawDestinationTransformedImage\[(\]+_XImage\[*\]+, int, int, _XImage\[*\]+, int, int, unsigned long, unsigned int, int, int, unsigned int, unsigned long, unsigned long, _XGC\[*\]+, (const ivTransformer|ivTransformer const)&&, int, int, int, int\[)\]+"
+ test_demangling_exact "gnu-v3: _ZN11RelateManip6EffectEO7ivEvent" "RelateManip::Effect(ivEvent&&)"
+ test_demangling_exact "gnu-v3: _ZN20DisplayList_IteratorC4EO11DisplayList" "DisplayList_Iterator::DisplayList_Iterator(DisplayList&&)"
+ test_demangling_exact "gnu-v3: _ZN3fooC4EOS_" "foo::foo(foo&&)"
+ test_demangling_exact "gnu-v3: _ZN3fooC4EiOS_iS0_iS0_" "foo::foo(int, foo&&, int, foo&&, int, foo&&)"
+ test_demangling "gnu-v3: _ZN7ivWorldC2EPKcOiPPcPK12ivOptionDescPK14ivPropertyData" \
+ "ivWorld::ivWorld\[(\]+(const char|char const)\[*\]+, int&&, char\[*\]+\[*\]+, (const ivOptionDesc|ivOptionDesc const)\[*\]+, (const ivPropertyData|ivPropertyData const)\[*\]+\[)\]+"
+ test_demangling "gnu-v3: _Z3argOK7Complex" \
+ "arg\[(\]+(const Complex|Complex const)&&\[)\]+"
+ test_demangling "gnu-v3: _ZNK9BitString8containsEOK10BitPattern" \
+ "BitString::contains\[(\]+(const BitPattern|BitPattern const)&&\[)\]+ const"
+ test_demangling "gnu-v3: _ZNK9BitString8containsEOK12BitSubStringi" \
+ "BitString::contains\[(\]+(const BitSubString|BitSubString const)&&, int\[)\]+ const"
+ test_demangling "gnu-v3: _ZNK9BitString8containsEOKS_" \
+ "BitString::contains\[(\]+(const BitString|BitString const)&&\[)\]+ const"
+ test_demangling_exact "gnu-v3: _ZN4ListI10VHDLEntityE3PixC4EOKS2_" \
+ "List<VHDLEntity>::Pix::Pix(List<VHDLEntity>::Pix const&&)"
+ test_demangling_exact "gnu-v3: _ZN4ListI10VHDLEntityE7elementC2EOKS0_PS2_" \
+ "List<VHDLEntity>::element::element(VHDLEntity const&&, List<VHDLEntity>::element*)"
+ test_demangling_exact "gnu-v3: _ZN4ListI10VHDLEntityE7elementC4EOKS2_" \
+ "List<VHDLEntity>::element::element(List<VHDLEntity>::element const&&)"
+ test_demangling_exact "gnu-v3: _ZNK4ListI10VHDLEntityEclEOKNS1_3PixE" \
+ "List<VHDLEntity>::operator()(List<VHDLEntity>::Pix const&&) const"
+ test_demangling_exact "gnu-v3: _ZN4ListI10VHDLEntityEC4EOKS1_" \
+ "List<VHDLEntity>::List(List<VHDLEntity> const&&)"
+ test_demangling_exact "gnu-v3: _ZN4PixXI11VHDLLibrary14VHDLLibraryRep4ListI10VHDLEntityEEC2EOKS5_" \
+ "PixX<VHDLLibrary, VHDLLibraryRep, List<VHDLEntity> >::PixX(PixX<VHDLLibrary, VHDLLibraryRep, List<VHDLEntity> > const&&)"
+ test_demangling_exact "gnu-v3: _ZNK11VHDLLibrary5nextEEO4PixXIS_14VHDLLibraryRep4ListI10VHDLEntityEE" \
+ "VHDLLibrary::nextE(PixX<VHDLLibrary, VHDLLibraryRep, List<VHDLEntity> >&&) const"
+ test_demangling_exact "gnu-v3: _ZNK4ListI10VHDLEntityE4nextEONS1_3PixE" \
+ "List<VHDLEntity>::next(List<VHDLEntity>::Pix&&) const"
+
## Buffer overrun. Should make GDB crash. Woo hoo!
test_demangling_exact "gnu: foo__I_4000000000000000000000000000000000000000000000000000000000000000000000000" "Can't demangle \"foo__I_4000000000000000000000000000000000000000000000000000000000000000000000000\""
diff --git a/gdb/testsuite/gdb.cp/rvalue-ref-casts.cc b/gdb/testsuite/gdb.cp/rvalue-ref-casts.cc
new file mode 100644
index 0000000..1f81fe0
--- /dev/null
+++ b/gdb/testsuite/gdb.cp/rvalue-ref-casts.cc
@@ -0,0 +1,75 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2002-2017 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* Rvalue references casting tests, based on casts.cc. */
+
+#include <utility>
+
+struct A
+{
+ int a;
+ A (int aa): a (aa) {}
+};
+
+struct B: public A
+{
+ int b;
+ B (int aa, int bb): A (aa), b (bb) {}
+};
+
+
+struct Alpha
+{
+ virtual void x () { }
+};
+
+struct Gamma
+{
+};
+
+struct Derived : public Alpha
+{
+};
+
+struct VirtuallyDerived : public virtual Alpha
+{
+};
+
+struct DoublyDerived : public VirtuallyDerived,
+ public virtual Alpha,
+ public Gamma
+{
+};
+
+int
+main (int argc, char **argv)
+{
+ A *a = new B (42, 1729);
+ B *b = (B *) a;
+ A &ar = *b;
+ B &br = (B&)ar;
+ A &&arr = std::move (A (42));
+ B &&brr = std::move (B (42, 1729));
+
+ Derived derived;
+ DoublyDerived doublyderived;
+
+ Alpha *ad = &derived;
+ Alpha *add = &doublyderived;
+
+ return 0; /* breakpoint spot: rvalue-ref-casts.exp: 1 */
+}
diff --git a/gdb/testsuite/gdb.cp/rvalue-ref-casts.exp b/gdb/testsuite/gdb.cp/rvalue-ref-casts.exp
new file mode 100644
index 0000000..f3a794c
--- /dev/null
+++ b/gdb/testsuite/gdb.cp/rvalue-ref-casts.exp
@@ -0,0 +1,77 @@
+# Copyright 2002-2017 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# This file is part of the gdb testsuite
+
+# C++11 rvalue reference type casting tests, based on gdb.cp/casts.exp.
+
+if {[skip_cplus_tests]} { continue }
+
+standard_testfile .cc
+
+if {[get_compiler_info "c++"]} {
+ return -1
+}
+
+if {[prepare_for_testing $testfile.exp $testfile $srcfile \
+ {debug c++ additional_flags="-std=gnu++11"}]} {
+ return -1
+}
+
+if {![runto_main]} {
+ untested "couldn't run to main"
+ return -1
+}
+
+# Prevent symbol on address 0x0 being printed.
+gdb_test_no_output "set print symbol off"
+
+set line [gdb_get_line_number {rvalue-ref-casts.exp: 1}]
+gdb_test "break $line" "Breakpoint.*at.* file .*$srcfile, line $line\\." \
+ "break at test location"
+
+gdb_test "continue" "Breakpoint .* at .*$srcfile:$line.*"
+
+# Check upcasting.
+gdb_test "print (A &&) br" ".* = .A &&.* {a = 42}" \
+ "cast derived class rvalue reference to base class rvalue reference"
+
+# Check downcasting.
+gdb_test "print (B &&) ar" ".* = .B.* {<A> = {a = 42}, b = 1729}" \
+ "cast base class rvalue reference to derived class rvalue reference"
+
+# Check compiler casting
+
+set nonzero_hex "0x\[0-9A-Fa-f\]\[0-9A-Fa-f\]+"
+
+gdb_test "print br" ".* = .B.* {<A> = {a = 42}, b = 1729}" \
+ "let compiler cast base class rvalue reference to derived\
+ class rvalue reference"
+
+gdb_test "print static_cast<A &&> (*b)" " = \\(A \\&\\&\\) @$hex: {a = 42}" \
+ "static_cast to rvalue reference type"
+
+gdb_test "print reinterpret_cast<A &&> (*b)" \
+ " = \\(A \\&\\&\\) @$hex: {a = 42}" \
+ "reinterpret_cast to rvalue reference type"
+
+gdb_test "print dynamic_cast<Alpha &&> (derived)" \
+ " = \\(Alpha \\&\\&\\) @$nonzero_hex: {.* = ${nonzero_hex}(\
+ <vtable for Derived.*>)?}" \
+ "dynamic_cast simple upcast to rvalue reference"
+
+gdb_test "print dynamic_cast<VirtuallyDerived &&> (*ad)" \
+ "dynamic_cast failed" \
+ "dynamic_cast to rvalue reference to non-existing base"
diff --git a/gdb/testsuite/gdb.cp/rvalue-ref-overload.cc b/gdb/testsuite/gdb.cp/rvalue-ref-overload.cc
new file mode 100644
index 0000000..c12eb03
--- /dev/null
+++ b/gdb/testsuite/gdb.cp/rvalue-ref-overload.cc
@@ -0,0 +1,86 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 1998-2017 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* Rvalue references overload tests for GDB, based on overload.cc. */
+
+#include <stddef.h>
+#include <utility>
+
+class foo;
+
+typedef foo &foo_lval_ref;
+typedef foo &&foo_rval_ref;
+
+class foo
+{
+public:
+ foo ();
+ foo (foo_lval_ref);
+ foo (foo_rval_ref);
+ ~foo ();
+
+ int overload1arg (foo_lval_ref);
+ int overload1arg (foo_rval_ref);
+};
+
+void
+marker1 ()
+{
+}
+
+static int
+f (int &x)
+{
+ return 1;
+}
+
+static int
+f (const int &x)
+{
+ return 2;
+}
+
+static int
+f (int &&x)
+{
+ return 3;
+}
+
+int
+main ()
+{
+ foo foo_rr_instance1;
+ foo arg;
+ int i = 0;
+ const int ci = 0;
+
+ // result = 1 + 2 + 3 + 3 = 9
+ int result = f (i) + f (ci) + f (0) + f (std::move (i));
+
+ marker1 (); // marker1-returns-here
+ return result;
+}
+
+foo::foo () {}
+foo::foo (foo_lval_ref afoo) {}
+foo::foo (foo_rval_ref afoo) {}
+foo::~foo () {}
+
+/* Some functions to test overloading by varying one argument type. */
+
+int foo::overload1arg (foo_lval_ref arg) { return 1; }
+int foo::overload1arg (foo_rval_ref arg) { return 2; }
diff --git a/gdb/testsuite/gdb.cp/rvalue-ref-overload.exp b/gdb/testsuite/gdb.cp/rvalue-ref-overload.exp
new file mode 100644
index 0000000..e729209
--- /dev/null
+++ b/gdb/testsuite/gdb.cp/rvalue-ref-overload.exp
@@ -0,0 +1,69 @@
+# Copyright 1998-2017 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# This file is part of the gdb testsuite
+
+# Tests for overloaded member functions with rvalue reference parameters,
+# based on gdb.cp/overload.exp.
+
+if {[skip_cplus_tests]} { continue }
+
+load_lib "cp-support.exp"
+
+standard_testfile .cc
+
+if {[prepare_for_testing $testfile.exp $testfile $srcfile \
+ {debug c++ additional_flags="-std=gnu++11"}]} {
+ return -1
+}
+
+# Set it up at a breakpoint so we can play with the variable values.
+
+if {![runto 'marker1']} {
+ untested "couldn't run to marker1"
+ return -1
+}
+
+# Prevent symbol on address 0x0 being printed.
+gdb_test_no_output "set print symbol off"
+gdb_test "up" ".*main.*" "up from marker1"
+
+# Print the monster class type.
+cp_test_ptype_class "foo_rr_instance1" "" "class" "foo" \
+ {
+ { method public "foo(void);" }
+ { method public "foo(foo_lval_ref);" }
+ { method public "foo(foo_rval_ref);" }
+ { method public "~foo();" }
+ { method public "int overload1arg(foo_lval_ref);" }
+ { method public "int overload1arg(foo_rval_ref);" }
+ }
+
+gdb_test "print foo_rr_instance1.overload1arg(arg)" \
+ "\\$\[0-9\]+ = 1" \
+ "print call overloaded func foo & arg"
+
+gdb_test "print foo_rr_instance1.overload1arg(static_cast<foo&&>(arg))" \
+ "\\$\[0-9\]+ = 2" \
+ "print call overloaded func foo && arg"
+
+# Test lvalue vs rvalue function overloads
+setup_kfail "c++/15372" "*-*-*"
+gdb_test "print f (i)" "= 1" "lvalue reference overload"
+
+gdb_test "print f (ci)" "= 2" "lvalue reference to const overload"
+
+setup_kfail "c++/15372" "*-*-*"
+gdb_test "print f (3)" "= 3" "rvalue reference overload"
diff --git a/gdb/testsuite/gdb.cp/rvalue-ref-params.cc b/gdb/testsuite/gdb.cp/rvalue-ref-params.cc
new file mode 100644
index 0000000..59f459b
--- /dev/null
+++ b/gdb/testsuite/gdb.cp/rvalue-ref-params.cc
@@ -0,0 +1,83 @@
+/* This test script is part of GDB, the GNU debugger.
+
+ Copyright 2006-2017 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* Rvalue reference parameter tests, based on ref-params.cc. */
+
+#include <utility>
+
+struct Parent
+{
+ Parent (int id0) : id (id0) { }
+ int id;
+};
+
+struct Child : public Parent
+{
+ Child (int id0) : Parent (id0) { }
+};
+
+int
+f1 (Parent &&R)
+{
+ return R.id; /* Set breakpoint marker3 here. */
+}
+
+int
+f2 (Child &&C)
+{
+ return f1 (std::move (C)); /* Set breakpoint marker2 here. */
+}
+
+struct OtherParent
+{
+ OtherParent (int other_id0) : other_id (other_id0) { }
+ int other_id;
+};
+
+struct MultiChild : public Parent, OtherParent
+{
+ MultiChild (int id0) : Parent (id0), OtherParent (id0 * 2) { }
+};
+
+int
+mf1 (OtherParent &&R)
+{
+ return R.other_id;
+}
+
+int
+mf2 (MultiChild &&C)
+{
+ return mf1 (std::move (C));
+}
+
+int
+main ()
+{
+ Child Q(40);
+ Child &QR = Q;
+
+ /* Set breakpoint marker1 here. */
+
+ f1 (Child (41));
+ f2 (Child (42));
+
+ MultiChild MQ (53);
+ MultiChild &MQR = MQ;
+
+ mf2 (std::move (MQ)); /* Set breakpoint MQ here. */
+}
diff --git a/gdb/testsuite/gdb.cp/rvalue-ref-params.exp b/gdb/testsuite/gdb.cp/rvalue-ref-params.exp
new file mode 100644
index 0000000..303b447
--- /dev/null
+++ b/gdb/testsuite/gdb.cp/rvalue-ref-params.exp
@@ -0,0 +1,69 @@
+# Copyright 2006-2017 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# Tests for rvalue reference parameters of types and their subtypes in GDB,
+# based on gdb.cp/ref-params.exp.
+
+if {[skip_cplus_tests]} { continue }
+
+standard_testfile .cc
+
+if {[prepare_for_testing $testfile.exp $testfile $srcfile \
+ {debug c++ additional_flags="-std=gnu++11"}] == 1} {
+ return -1
+}
+
+proc gdb_start_again {text prefix} {
+ global binfile
+ global srcfile
+
+ with_test_prefix $prefix {
+ clean_restart $binfile
+
+ runto ${srcfile}:[gdb_get_line_number $text]
+ }
+}
+
+set t "print value of f1 on (Child&&) in main"
+gdb_start_again "marker1 here" $t
+gdb_test "print f1(static_cast<Child&&>(Q))" ".* = 40.*" $t
+
+set t "print value of f2 on (Child&&) in main"
+gdb_start_again "marker1 here" $t
+gdb_test "print f2(static_cast<Child&&>(Q))" ".* = 40.*" $t
+
+set t "print value of Child&& in f2"
+gdb_start_again "marker2 here" $t
+gdb_test "print C" ".*id = 42.*" $t
+
+setup_kfail "c++/15372" "*-*-*"
+gdb_test "print f1 (static_cast<Child&&> (C))" ".* = 42.*" \
+ "print value of f1 on Child&& in f2"
+
+set t "print value of Parent&& in f1"
+gdb_start_again "marker3 here" $t
+gdb_test "print R" ".*id = 41.*" $t
+
+set t "print f1(static_cast<MultiChild&&>(MQ))"
+gdb_start_again "breakpoint MQ here" $t
+gdb_test $t ".* = 53"
+
+set t "print mf1(static_cast<MultiChild&&>(MQ))"
+gdb_start_again "breakpoint MQ here" $t
+gdb_test $t ".* = 106"
+
+set t "print mf2(static_cast<MultiChild&&>(MQ))"
+gdb_start_again "breakpoint MQ here" $t
+gdb_test $t ".* = 106"
diff --git a/gdb/testsuite/gdb.cp/rvalue-ref-sizeof.cc b/gdb/testsuite/gdb.cp/rvalue-ref-sizeof.cc
new file mode 100644
index 0000000..ab42c67
--- /dev/null
+++ b/gdb/testsuite/gdb.cp/rvalue-ref-sizeof.cc
@@ -0,0 +1,75 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2014-2017 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* Sizeof tests for rvalue references, based on cpsizeof.cc. */
+
+#include <utility>
+
+struct Class
+{
+ int a;
+ char b;
+ long c;
+
+ Class () : a (1), b ('2'), c (3) { }
+};
+
+union Union
+{
+ Class *kp;
+ char a;
+ int b;
+ long c;
+};
+
+enum Enum { A, B, C, D };
+
+typedef unsigned char a4[4];
+typedef unsigned char a8[8];
+typedef unsigned char a12[12];
+typedef Class c4[4];
+typedef Union u8[8];
+typedef Enum e12[12];
+
+#define T(N) \
+ N N ## obj; \
+ N&& N ## _rref = std::move (N ## obj); \
+ N* N ## p = &(N ## obj); \
+ N*&& N ## p_rref = std::move (N ## p); \
+ int size_ ## N = sizeof (N ## _rref); \
+ int size_ ## N ## p = sizeof (N ## p_rref); \
+
+int
+main ()
+{
+ T (char);
+ T (int);
+ T (long);
+ T (float);
+ T (double);
+ T (a4);
+ T (a8);
+ T (a12);
+ T (Class);
+ T (Union);
+ T (Enum);
+ T (c4);
+ T (u8);
+ T (e12);
+
+ return 0; /* break here */
+}
diff --git a/gdb/testsuite/gdb.cp/rvalue-ref-sizeof.exp b/gdb/testsuite/gdb.cp/rvalue-ref-sizeof.exp
new file mode 100644
index 0000000..c6c2d21
--- /dev/null
+++ b/gdb/testsuite/gdb.cp/rvalue-ref-sizeof.exp
@@ -0,0 +1,43 @@
+# Copyright 2014-2017 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# sizeof() tests with rvalue reference parameter types, based on
+# gdb.cp/cpsizeof.exp.
+
+standard_testfile .cc
+
+if {[skip_cplus_tests]} { continue }
+
+if {[prepare_for_testing ${testfile}.exp $testfile $srcfile \
+ {debug c++ additional_flags="-std=gnu++11"}] } {
+ return -1
+}
+
+if {![runto_main]} {
+ perror "could not run to main"
+ continue
+}
+
+gdb_breakpoint [gdb_get_line_number "break here"]
+gdb_continue_to_breakpoint "break here"
+
+# Compare sizeof from the compiler and gdb. Do this once with the actual
+# type name and once with a reference variable.
+foreach v {char int long float double a4 a8 a12 Class Union Enum c4 u8 e12} {
+ gdb_test "print size_$v == sizeof (${v}&&)" "= true"
+ gdb_test "print size_$v == sizeof (${v}_rref)" "= true"
+ gdb_test "print size_${v}p == sizeof (${v}*&&)" "= true"
+ gdb_test "print size_${v}p == sizeof (${v}p_rref)" "= true"
+}
diff --git a/gdb/testsuite/gdb.cp/rvalue-ref-types.cc b/gdb/testsuite/gdb.cp/rvalue-ref-types.cc
new file mode 100644
index 0000000..bd8865c
--- /dev/null
+++ b/gdb/testsuite/gdb.cp/rvalue-ref-types.cc
@@ -0,0 +1,79 @@
+/* This test script is part of GDB, the GNU debugger.
+
+ Copyright 1999-2017 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* Tests for reference types with short type variables in GDB, based on
+ gdb.cp/ref-types.cc. */
+
+#include <utility>
+
+int main2 ();
+
+void
+marker1 ()
+{
+}
+
+int
+main ()
+{
+ short t = -1;
+ short *pt;
+ short &&rrt = std::move (t);
+ pt = &rrt;
+
+ short *&&rrpt = std::move (pt);
+ short at[4];
+ at[0] = 0;
+ at[1] = 1;
+ at[2] = 2;
+ at[3] = 3;
+
+ short (&&rrat)[4] = std::move( at);
+
+ marker1();
+
+ main2();
+
+ return 0;
+}
+
+int
+f ()
+{
+ int f1;
+ f1 = 1;
+ return f1;
+}
+
+int
+main2 ()
+{
+ char &&rrC = 'A';
+ unsigned char &&rrUC = 21;
+ short &&rrS = -14;
+ unsigned short &&rrUS = 7;
+ int &&rrI = 102;
+ unsigned int &&rrUI = 1002;
+ long &&rrL = -234;
+ unsigned long &&rrUL = 234;
+ float &&rrF = 1.25E10;
+ double &&rrD = -1.375E-123;
+
+ f ();
+
+ return 0;
+}
diff --git a/gdb/testsuite/gdb.cp/rvalue-ref-types.exp b/gdb/testsuite/gdb.cp/rvalue-ref-types.exp
new file mode 100644
index 0000000..61be9d0
--- /dev/null
+++ b/gdb/testsuite/gdb.cp/rvalue-ref-types.exp
@@ -0,0 +1,128 @@
+# Copyright 1999-2017 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# Tests for reference types with short type variables in GDB, based on
+# gdb.cp/ref-types.exp.
+
+if { [skip_cplus_tests] } { continue }
+
+standard_testfile .cc
+
+if {[prepare_for_testing $testfile.exp $testfile $srcfile \
+ {debug c++ additional_flags="-std=gnu++11"}]} {
+ return -1
+}
+
+#
+# Set it up at a breakpoint so we can play with the variable values.
+#
+if {![runto_main]} {
+ untested "couldn't run to breakpoint"
+ return -1
+}
+
+if {![runto 'marker1']} {
+ untested "couldn't run to marker1"
+ return -1
+}
+
+gdb_test "up" ".*main.*" "up from marker1 1"
+
+gdb_test "print rrt" " = \\(short( int)? &&\\) @$hex: -1" "print value of rrt"
+
+gdb_test "ptype rrt" "type = short( int)? &&" "ptype rrt"
+
+gdb_test "print *rrpt" ".$decimal = -1" "print value of *rrpt"
+
+# gdb had a bug about dereferencing a pointer type
+# that would lead to wrong results
+# if we try to examine memory at pointer value.
+
+gdb_test "x /hd rrpt" "$hex:\[ \t\]*-1" "examine value at rrpt"
+
+gdb_test "ptype rrpt" "type = short( int)? \\*&&" "ptype rrpt"
+
+gdb_test "print rrat\[0\]" ".$decimal = 0" "print value of rrat\[0\]"
+
+gdb_test "ptype rrat" "type = short( int)? \\\(&&\\\)\\\[4\\\]" "ptype rrat"
+
+gdb_test "print rrat\[1\]" ".$decimal = 1" "print value of rrat\[1\]"
+gdb_test "print rrat\[2\]" ".$decimal = 2" "print value of rrat\[2\]"
+gdb_test "print rrat\[3\]" ".$decimal = 3" "print value of rrat\[3\]"
+
+
+if {![runto 'f']} then {
+ perror "couldn't run to f"
+ continue
+}
+
+gdb_test "up" ".main2.*" "up from f"
+
+gdb_test "ptype rrC" "type = char &&"
+
+gdb_test "ptype rrUC" "type = unsigned char &&"
+
+gdb_test "ptype rrS" "type = short( int)? &&" "ptype rrS"
+
+gdb_test "ptype rrUS" "type = unsigned short( int)? &&" "ptype rrUS"
+
+gdb_test "ptype rrI" "type = int &&"
+
+gdb_test "ptype rrUI" "type = unsigned int &&"
+
+gdb_test "ptype rrL" "type = long( int)? &&" "ptype rrL"
+
+gdb_test "ptype rrUL" "type = unsigned long( int)? &&" "ptype rrUL"
+
+gdb_test "ptype rrF" "type = float &&"
+
+gdb_test "ptype rrD" "type = double &&"
+
+gdb_test "print rrC" "$decimal = \\(char &&\\) @$hex: 65 \'A\'" \
+ "print value of rrC"
+
+gdb_test "print rrUC" \
+ "$decimal = \\(unsigned char &&\\) @$hex: 21 \'.025\'" \
+ "print value of rrUC"
+
+gdb_test "print rrS" "$decimal = \\(short( int)? &&\\) @$hex: -14" \
+ "print value of rrS"
+
+gdb_test "print rrUS" \
+ "$decimal = \\(unsigned short( int)? &&\\) @$hex: 7" \
+ "print value of rrUS"
+
+gdb_test "print rrI" "$decimal = \\(int &&\\) @$hex: 102" \
+ "print value of rrI"
+
+gdb_test "print rrUI" \
+ "$decimal = \\(unsigned int &&\\) @$hex: 1002" \
+ "print value of rrUI"
+
+gdb_test "print rrL" \
+ "$decimal = \\(long( int)? &&\\) @$hex: -234" \
+ "print value of rrL"
+
+gdb_test "print rrUL" \
+ "$decimal = \\((unsigned long|long unsigned int)? &&\\) @$hex: 234" \
+ "print value of rrUL"
+
+gdb_test "print rrF" \
+ "$decimal = \\(float &&\\) @$hex: 1.2${decimal}e\\+0?10.*" \
+ "print value of rrF"
+
+gdb_test "print rrD" \
+ "$decimal = \\(double &&\\) @$hex: -1.375e-123.*" \
+ "print value of rrD"
diff --git a/gdb/testsuite/gdb.python/py-rvalue-ref-value-cc.cc b/gdb/testsuite/gdb.python/py-rvalue-ref-value-cc.cc
new file mode 100644
index 0000000..8943be1
--- /dev/null
+++ b/gdb/testsuite/gdb.python/py-rvalue-ref-value-cc.cc
@@ -0,0 +1,59 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2012-2017 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* Test rvalue references in python. Based on py-value-cc.cc. */
+
+#include <utility>
+
+class A
+{
+public:
+ int operator+ (const int a1);
+
+ public:
+ int a;
+};
+
+int
+A::operator+ (const int a1)
+{
+ return a + a1;
+}
+
+class B : public A
+{
+ public:
+ char a;
+};
+
+typedef int *int_ptr;
+
+int
+main ()
+{
+ int val = 10;
+ int &&int_rref = std::move (val);
+ int_ptr ptr = &val;
+ int_ptr &&int_ptr_rref = std::move (ptr);
+
+ B b;
+ b.a = 'b';
+ (&b)->A::a = 100;
+ B &&b_rref = std::move (b);
+
+ return 0; /* Break here. */
+}
diff --git a/gdb/testsuite/gdb.python/py-rvalue-ref-value-cc.exp b/gdb/testsuite/gdb.python/py-rvalue-ref-value-cc.exp
new file mode 100644
index 0000000..dde5a94
--- /dev/null
+++ b/gdb/testsuite/gdb.python/py-rvalue-ref-value-cc.exp
@@ -0,0 +1,57 @@
+# Copyright (C) 2012-2017 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# This file is part of the GDB testsuite. It tests the mechanism
+# exposing rvalue reference values to Python. It is based on
+# gdb.python/py-value-cc.exp.
+
+if {[skip_cplus_tests]} { continue }
+
+standard_testfile .cc
+
+if {[prepare_for_testing $testfile.exp $testfile $srcfile \
+ {debug c++ additional_flags="-std=c++11"}]} {
+ return -1
+}
+
+# Skip all tests if Python scripting is not enabled.
+if {[skip_python_tests]} { continue }
+
+if {![runto_main]} {
+ untested "couldn't run to main"
+ return -1
+}
+
+gdb_breakpoint [gdb_get_line_number "Break here."]
+gdb_continue_to_breakpoint "Break here" ".*Break here.*"
+
+gdb_test "python print (str(gdb.parse_and_eval(\"int_rref\").type))" "int &&"
+gdb_test "python print (str(gdb.parse_and_eval(\"int_rref\").referenced_value().type))" "int"
+gdb_test "python print (str(gdb.parse_and_eval(\"int_rref\").referenced_value()))" "10"
+
+gdb_test "python print (str(gdb.parse_and_eval(\"int_ptr_rref\").dereference().type))" "int"
+gdb_test "python print (str(gdb.parse_and_eval(\"int_ptr_rref\").referenced_value().type))" "int_ptr"
+gdb_test "python print (str(gdb.parse_and_eval(\"int_ptr_rref\").referenced_value().dereference()))" "10"
+gdb_test "python print (str(gdb.parse_and_eval(\"int_ptr_rref\").referenced_value().referenced_value()))" "10"
+
+gdb_test_no_output "python b = gdb.parse_and_eval('b')" "init b"
+gdb_test_no_output "python b_rref = gdb.parse_and_eval('b_rref')" "init b_rref"
+gdb_test_no_output "python b_fields = b.type.fields()" "init b_fields"
+
+gdb_test "python print(b_rref\[b_fields\[1\]\])" "98 'b'" "b_rref.a via field"
+gdb_test "python print(b_rref\[b_fields\[0\]\].type.target())" "A" \
+ "type of b_rref's base class via field"
+gdb_test "python print(b_rref\[b_fields\[0\]\]\['a'\])" "100" \
+ "b_rref.A::a via field"