From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16671 invoked by alias); 14 Mar 2017 18:15:43 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 16489 invoked by uid 89); 14 Mar 2017 18:15:33 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-21.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,KAM_TK,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=5216 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 14 Mar 2017 18:15:27 +0000 Received: from smtp.corp.redhat.com (int-mx16.intmail.prod.int.phx2.redhat.com [10.5.11.28]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9D7C681244 for ; Tue, 14 Mar 2017 18:15:16 +0000 (UTC) Received: from valrhona.uglyboxes.com (ovpn04.gateway.prod.ext.phx2.redhat.com [10.5.9.4]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EB97A2D655; Tue, 14 Mar 2017 18:15:15 +0000 (UTC) Subject: Re: [PATCH v6 11/11] Add rvalue reference tests and NEWS entry To: Pedro Alves , gdb-patches@sourceware.org References: <1489176286-27973-1-git-send-email-keiths@redhat.com> <1489176286-27973-12-git-send-email-keiths@redhat.com> From: Keith Seitz Message-ID: <58C83332.1020603@redhat.com> Date: Tue, 14 Mar 2017 18:15:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.1.0 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/mixed; boundary="------------060500080008050500010704" X-IsSubscribed: yes X-SW-Source: 2017-03/txt/msg00244.txt.bz2 This is a multi-part message in MIME format. --------------060500080008050500010704 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 8bit Content-length: 1714 On 03/13/2017 11:52 AM, Pedro Alves wrote: > > Typo, "ravlue". > All corrected. >> +set line [gdb_get_line_number {rvalue-ref-casts.exp: 1}] >> +gdb_test "break $line" "Breakpoint.*at.* file .*$srcfile, line $line\\." > > Please add an explicit test message in order to avoid it changing > if/when $line changes. Fixed. > Is there a special reason for using concat here? I'd think a > continuation would do: > > "let compiler cast base class rvalue reference to derived\ > class rvalue reference" > > TCL replaces continuation+newline+spaces/tabs with a single whitespace: > http://www.tcl.tk/man/tcl8.5/TclCmd/Tcl.htm#M24 > Ha. I'm such an old dog! [And learned/was reminded of a new trick...] Fixed. >> + >> +# >> +# test running programs >> +# I've removed the above comment from all the rvalue-*.exp tests. They don't actually serve to clarify anything anyway. >> +proc gdb_start_again {text} { >> + global binfile >> + global srcfile >> + >> + clean_restart $binfile >> + >> + runto ${srcfile}:[gdb_get_line_number $text] > > Should probably be wrapped with with_test_prefix to avoid > duplicate messages from within clean_restart / runto, > in case they fail. Fixed. >> + short (&&rrat)[4] = std::move( at); >> + >> + marker1(); >> + >> + main2(); >> + >> + return 0; > > Indentation of these 3 statements above is odd. > Yup. Fixed. > > Same comment about with_test_prefix. Actually, can we just > remove the "eof" handling below making this procedure > unnecessary? (I know this is copied from the other file.) > Indeed. I've replaced the gdb_test_multiple with the simpler gdb_test and removed the gdb_start_again procedure. Revision attached. Keith --------------060500080008050500010704 Content-Type: text/x-patch; name="add-rvalue-tests-and-doc.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline; filename="add-rvalue-tests-and-doc.patch" Content-length: 37307 commit 25826f564b480af57a1da01c0f76c4b61034485e Author: Artemiy Volkov Date: Wed Jan 25 10:33:56 2017 -0800 Add rvalue reference tests and docs =20=20=20=20 This patch adds tests for the initial rvalue reference support patchset= . All of the new tests are practically mirrored regular references tests and,= except for the demangler ones, are introduced in new files, which are set to be compiled with -std=3Dgnu++11. Tested are printing of rvalue reference = types and values, rvalue reference parameters in function overloading, demangling= of function names containing rvalue reference parameters, casts to rvalue reference types, application of the sizeof operator to rvalue reference= types and values, and support for rvalue references within the gdb python mod= ule. =20=20=20=20 gdb/ChnageLog =20=20=20=20 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. =20=20=20=20 gdb/testsuite/ChangeLog =20=20=20=20 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. diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 544f192..7876b47 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,6 +1,13 @@ 2017-MM-DD Artemiy Volkov =20 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-MM-DD Artemiy Volkov + + PR gdb/14441 * gdbtypes.c (rank_one_type): Implement overloading resolution rules regarding rvalue references. =20 diff --git a/gdb/NEWS b/gdb/NEWS index cf58595..4fade30 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. =20 +* GDB now supports C++11 rvalue references. + * Python Scripting =20 ** New functions to start, stop and access a running btrace recording. + ** Rvalue references are now supported in gdb.Type. =20 * 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 5cf0f97..581ddae 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -14827,9 +14827,9 @@ see @ref{Completion, ,Command Completion}. =20 @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 automatica= lly -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. =20 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 0718d76..fb41311 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,21 @@ +2017-MM-DD Artemiy Volkov + Keith Seitz + + 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-10 Keith Seitz =20 PR c++/8128 diff --git a/gdb/testsuite/gdb.cp/demangle.exp b/gdb/testsuite/gdb.cp/deman= gle.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} { } =20 if {[string compare $style $current_demangling_style]} { - set_demangling_style $style + with_test_prefix $test { + set_demangling_style $style + } } =20 $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\"" =20 + # Rvalue reference tests + test_demangling_exact "gnu-v3: _ZN9ArrowLine19ArrowheadIntersectsEP9Ar= rowheadO6BoxObjP7Graphic" "ArrowLine::ArrowheadIntersects(Arrowhead*, BoxOb= j&&, Graphic*)" + test_demangling "gnu-v3: _Z13BitPatterntoaOK10BitPatternccc" \ + "BitPatterntoa\[(\]+(const BitPattern|BitPattern const)&&, char, char, ch= ar\[)\]+" + test_demangling_exact "gnu-v3: _ZN8TextCode14CoreConstDeclsEO7ostream"= "TextCode::CoreConstDecls(ostream&&)" + test_demangling "gnu-v3: _Z31DrawDestinationTransformedImageP7_XImagei= iS0_iimjiijmmP4_XGCOK13ivTransformeriiii" \ + "DrawDestinationTransformedImage\[(\]+_XImage\[*\]+, int, int, _XImage\[*= \]+, int, int, unsigned long, unsigned int, int, int, unsigned int, unsigne= d long, unsigned long, _XGC\[*\]+, (const ivTransformer|ivTransformer const= )&&, int, int, int, int\[)\]+" + test_demangling_exact "gnu-v3: _ZN11RelateManip6EffectEO7ivEvent" "Rel= ateManip::Effect(ivEvent&&)" + test_demangling_exact "gnu-v3: _ZN20DisplayList_IteratorC4EO11DisplayL= ist" "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: _ZN7ivWorldC2EPKcOiPPcPK12ivOptionDescPK14ivP= ropertyData" \ + "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)&&\[)\]+ con= st" + 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::Pix::Pix(List::Pix const&&)" + test_demangling_exact "gnu-v3: _ZN4ListI10VHDLEntityE7elementC2EOKS0_P= S2_" \ + "List::element::element(VHDLEntity const&&, List:= :element*)" + test_demangling_exact "gnu-v3: _ZN4ListI10VHDLEntityE7elementC4EOKS2_"= \ + "List::element::element(List::element const&&)" + test_demangling_exact "gnu-v3: _ZNK4ListI10VHDLEntityEclEOKNS1_3PixE" \ + "List::operator()(List::Pix const&&) const" + test_demangling_exact "gnu-v3: _ZN4ListI10VHDLEntityEC4EOKS1_" \ + "List::List(List const&&)" + test_demangling_exact "gnu-v3: _ZN4PixXI11VHDLLibrary14VHDLLibraryRep4= ListI10VHDLEntityEEC2EOKS5_" \ + "PixX >::PixX(PixX > const&&)" + test_demangling_exact "gnu-v3: _ZNK11VHDLLibrary5nextEEO4PixXIS_14VHDL= LibraryRep4ListI10VHDLEntityEE" \ + "VHDLLibrary::nextE(PixX >&= &) const" + test_demangling_exact "gnu-v3: _ZNK4ListI10VHDLEntityE4nextEONS1_3PixE= " \ + "List::next(List::Pix&&) const" + ## Buffer overrun. Should make GDB crash. Woo hoo! test_demangling_exact "gnu: foo__I_40000000000000000000000000000000000= 00000000000000000000000000000000000000" "Can't demangle \"foo__I_4000000000= 000000000000000000000000000000000000000000000000000000000000000\"" =20 diff --git a/gdb/testsuite/gdb.cp/rvalue-ref-casts.cc b/gdb/testsuite/gdb.c= p/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 . = */ + +/* Rvalue references casting tests, based on casts.cc. */ + +#include + +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 =3D new B (42, 1729); + B *b =3D (B *) a; + A &ar =3D *b; + B &br =3D (B&)ar; + A &&arr =3D std::move (A (42)); + B &&brr =3D std::move (B (42, 1729)); + + Derived derived; + DoublyDerived doublyderived; + + Alpha *ad =3D &derived; + Alpha *add =3D &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 . + +# 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=3D"-std=3Dgnu++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" ".* =3D .A &&.* {a =3D 42}" \ + "cast derived class rvalue reference to base class rvalue reference" + +# Check downcasting. +gdb_test "print (B &&) ar" ".* =3D .B.* { =3D {a =3D 42}, b =3D 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" ".* =3D .B.* { =3D {a =3D 42}, b =3D 1729}" \ + "let compiler cast base class rvalue reference to derived\ + class rvalue reference" + +gdb_test "print static_cast (*b)" " =3D \\(A \\&\\&\\) @$hex: {a =3D= 42}" \ + "static_cast to rvalue reference type" + +gdb_test "print reinterpret_cast (*b)" \ + " =3D \\(A \\&\\&\\) @$hex: {a =3D 42}" \ + "reinterpret_cast to rvalue reference type" + +gdb_test "print dynamic_cast (derived)" \ + " =3D \\(Alpha \\&\\&\\) @$nonzero_hex: {.* =3D ${nonzero_hex}(\ + )?}" \ + "dynamic_cast simple upcast to rvalue reference" + +gdb_test "print dynamic_cast (*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/gd= b.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 . = */ + +/* Rvalue references overload tests for GDB, based on overload.cc. */ + +#include +#include + +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 =3D 0; + const int ci =3D 0; + + // result =3D 1 + 2 + 3 + 3 =3D 9 + int result =3D 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/g= db.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 . + +# 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=3D"-std=3Dgnu++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\]+ =3D 1" \ + "print call overloaded func foo & arg" + +gdb_test "print foo_rr_instance1.overload1arg(static_cast(arg))" \ + "\\$\[0-9\]+ =3D 2" \ + "print call overloaded func foo && arg" + +# Test lvalue vs rvalue function overloads +setup_kfail "c++/15372" "*-*-*" +gdb_test "print f (i)" "=3D 1" "lvalue reference overload" + +gdb_test "print f (ci)" "=3D 2" "lvalue reference to const overload" + +setup_kfail "c++/15372" "*-*-*" +gdb_test "print f (3)" "=3D 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 . = */ + +/* Rvalue reference parameter tests, based on ref-params.cc. */ + +#include + +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 her= e. */ +} + +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 =3D Q; + + /* Set breakpoint marker1 here. */ + + f1 (Child (41)); + f2 (Child (42)); + + MultiChild MQ (53); + MultiChild &MQR =3D 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 . + +# 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=3D"-std=3Dgnu++11"}] =3D=3D 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(Q))" ".* =3D 40.*" $t + +set t "print value of f2 on (Child&&) in main"=20 +gdb_start_again "marker1 here" $t +gdb_test "print f2(static_cast(Q))" ".* =3D 40.*" $t + +set t "print value of Child&& in f2" +gdb_start_again "marker2 here" $t +gdb_test "print C" ".*id =3D 42.*" $t + +setup_kfail "c++/15372" "*-*-*" +gdb_test "print f1 (static_cast (C))" ".* =3D 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 =3D 41.*" $t + +set t "print f1(static_cast(MQ))" +gdb_start_again "breakpoint MQ here" $t +gdb_test $t ".* =3D 53" + +set t "print mf1(static_cast(MQ))" +gdb_start_again "breakpoint MQ here" $t +gdb_test $t ".* =3D 106" + +set t "print mf2(static_cast(MQ))" +gdb_start_again "breakpoint MQ here" $t +gdb_test $t ".* =3D 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 . = */ + +/* Sizeof tests for rvalue references, based on cpsizeof.cc. */ + +#include + +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 =3D std::move (N ## obj); \ + N* N ## p =3D &(N ## obj); \ + N*&& N ## p_rref =3D std::move (N ## p); \ + int size_ ## N =3D sizeof (N ## _rref); \ + int size_ ## N ## p =3D 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 . + +# 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=3D"-std=3Dgnu++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 =3D=3D sizeof (${v}&&)" "=3D true" + gdb_test "print size_$v =3D=3D sizeof (${v}_rref)" "=3D true" + gdb_test "print size_${v}p =3D=3D sizeof (${v}*&&)" "=3D true" + gdb_test "print size_${v}p =3D=3D sizeof (${v}p_rref)" "=3D true" +} diff --git a/gdb/testsuite/gdb.cp/rvalue-ref-types.cc b/gdb/testsuite/gdb.c= p/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 . = */ + +/* Tests for reference types with short type variables in GDB, based on + gdb.cp/ref-types.cc. */ + +#include + +int main2 (); + +void +marker1 () +{ +} + +int +main () +{ + short t =3D -1; + short *pt; + short &&rrt =3D std::move (t); + pt =3D &rrt; + + short *&&rrpt =3D std::move (pt); + short at[4]; + at[0] =3D 0; + at[1] =3D 1; + at[2] =3D 2; + at[3] =3D 3; + + short (&&rrat)[4] =3D std::move( at); + + marker1(); + + main2(); + + return 0; +} + +int +f () +{ + int f1; + f1 =3D 1; + return f1; +} + +int +main2 () +{ + char &&rrC =3D 'A'; + unsigned char &&rrUC =3D 21; + short &&rrS =3D -14; + unsigned short &&rrUS =3D 7; + int &&rrI =3D 102; + unsigned int &&rrUI =3D 1002; + long &&rrL =3D -234; + unsigned long &&rrUL =3D 234; + float &&rrF =3D 1.25E10; + double &&rrD =3D -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 . + +# 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=3D"-std=3Dgnu++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" " =3D \\(short( int)? &&\\) @$hex: -1" "print value o= f rrt"=20 + +gdb_test "ptype rrt" "type =3D short( int)? &&" "ptype rrt" + +gdb_test "print *rrpt" ".$decimal =3D -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 =3D short( int)? \\*&&" "ptype rrpt" + +gdb_test "print rrat\[0\]" ".$decimal =3D 0" "print value of rrat\[0\]" + +gdb_test "ptype rrat" "type =3D short( int)? \\\(&&\\\)\\\[4\\\]" "ptype r= rat" + +gdb_test "print rrat\[1\]" ".$decimal =3D 1" "print value of rrat\[1\]" +gdb_test "print rrat\[2\]" ".$decimal =3D 2" "print value of rrat\[2\]" +gdb_test "print rrat\[3\]" ".$decimal =3D 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 =3D char &&" + +gdb_test "ptype rrUC" "type =3D unsigned char &&" + +gdb_test "ptype rrS" "type =3D short( int)? &&" "ptype rrS" + +gdb_test "ptype rrUS" "type =3D unsigned short( int)? &&" "ptype rrUS" + +gdb_test "ptype rrI" "type =3D int &&" + +gdb_test "ptype rrUI" "type =3D unsigned int &&" + +gdb_test "ptype rrL" "type =3D long( int)? &&" "ptype rrL" + +gdb_test "ptype rrUL" "type =3D unsigned long( int)? &&" "ptype rrUL" + +gdb_test "ptype rrF" "type =3D float &&" + +gdb_test "ptype rrD" "type =3D double &&" + +gdb_test "print rrC" "$decimal =3D \\(char &&\\) @$hex: 65 \'A\'" \ + "print value of rrC" + +gdb_test "print rrUC" \ + "$decimal =3D \\(unsigned char &&\\) @$hex: 21 \'.025\'" \ + "print value of rrUC" + +gdb_test "print rrS" "$decimal =3D \\(short( int)? &&\\) @$hex: -14" \ + "print value of rrS" + +gdb_test "print rrUS" \ + "$decimal =3D \\(unsigned short( int)? &&\\) @$hex: 7" \ + "print value of rrUS" + +gdb_test "print rrI" "$decimal =3D \\(int &&\\) @$hex: 102" \ + "print value of rrI" + +gdb_test "print rrUI" \ + "$decimal =3D \\(unsigned int &&\\) @$hex: 1002" \ + "print value of rrUI" + +gdb_test "print rrL" \ + "$decimal =3D \\(long( int)? &&\\) @$hex: -234" \ + "print value of rrL" + +gdb_test "print rrUL" \ + "$decimal =3D \\((unsigned long|long unsigned int)? &&\\) @$hex: 234" \ + "print value of rrUL" + +gdb_test "print rrF" \ + "$decimal =3D \\(float &&\\) @$hex: 1.2${decimal}e\\+0?10.*" \ + "print value of rrF" + +gdb_test "print rrD" \ + "$decimal =3D \\(double &&\\) @$hex: -1.375e-123.*" \ + "print value of rrD" diff --git a/gdb/testsuite/gdb.python/py-rvalue-ref-value-cc.cc b/gdb/tests= uite/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 . = */ + +/* Test rvalue references in python. Based on py-value-cc.cc. */ + +#include + +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 =3D 10; + int &&int_rref =3D std::move (val); + int_ptr ptr =3D &val; + int_ptr &&int_ptr_rref =3D std::move (ptr); + + B b; + b.a =3D 'b'; + (&b)->A::a =3D 100; + B &&b_rref =3D std::move (b); + + return 0; /* Break here. */ +} diff --git a/gdb/testsuite/gdb.python/py-rvalue-ref-value-cc.exp b/gdb/test= suite/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 . + +# 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=3D"-std=3Dc++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_va= lue().type))" "int" +gdb_test "python print (str(gdb.parse_and_eval(\"int_rref\").referenced_va= lue()))" "10" + +gdb_test "python print (str(gdb.parse_and_eval(\"int_ptr_rref\").dereferen= ce().type))" "int" +gdb_test "python print (str(gdb.parse_and_eval(\"int_ptr_rref\").reference= d_value().type))" "int_ptr" +gdb_test "python print (str(gdb.parse_and_eval(\"int_ptr_rref\").reference= d_value().dereference()))" "10" +gdb_test "python print (str(gdb.parse_and_eval(\"int_ptr_rref\").reference= d_value().referenced_value()))" "10" + +gdb_test_no_output "python b =3D gdb.parse_and_eval('b')" "init b" +gdb_test_no_output "python b_rref =3D gdb.parse_and_eval('b_rref')" "init = b_rref" +gdb_test_no_output "python b_fields =3D b.type.fields()" "init b_fields" + +gdb_test "python print(b_rref\[b_fields\[1\]\])" "98 'b'" "b_rref.a via fi= eld" +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" --------------060500080008050500010704--