rvalue-ref-casts.exp revision 1.1.1.4
1# Copyright 2002-2023 Free Software Foundation, Inc. 2 3# This program is free software; you can redistribute it and/or modify 4# it under the terms of the GNU General Public License as published by 5# the Free Software Foundation; either version 3 of the License, or 6# (at your option) any later version. 7# 8# This program is distributed in the hope that it will be useful, 9# but WITHOUT ANY WARRANTY; without even the implied warranty of 10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11# GNU General Public License for more details. 12# 13# You should have received a copy of the GNU General Public License 14# along with this program. If not, see <http://www.gnu.org/licenses/>. 15 16# This file is part of the gdb testsuite 17 18# C++11 rvalue reference type casting tests, based on gdb.cp/casts.exp. 19 20if {[skip_cplus_tests]} { continue } 21 22standard_testfile .cc 23 24if {[prepare_for_testing $testfile.exp $testfile $srcfile \ 25 {debug c++ additional_flags="-std=gnu++11"}]} { 26 return -1 27} 28 29if {![runto_main]} { 30 return -1 31} 32 33# Prevent symbol on address 0x0 being printed. 34gdb_test_no_output "set print symbol off" 35 36set line [gdb_get_line_number {rvalue-ref-casts.exp: 1}] 37gdb_test "break $line" "Breakpoint.*at.* file .*$srcfile, line $line\\." \ 38 "break at test location" 39 40gdb_test "continue" "Breakpoint .* at .*$srcfile:$line.*" 41 42# Check upcasting. 43gdb_test "print (A &&) br" ".* = .A &&.* {a = 42}" \ 44 "cast derived class rvalue reference to base class rvalue reference" 45 46# Check downcasting. 47gdb_test "print (B &&) ar" ".* = .B.* {<A> = {a = 42}, b = 1729}" \ 48 "cast base class rvalue reference to derived class rvalue reference" 49 50# Check compiler casting 51 52set nonzero_hex "0x\[0-9A-Fa-f\]\[0-9A-Fa-f\]+" 53 54gdb_test "print br" ".* = .B.* {<A> = {a = 42}, b = 1729}" \ 55 "let compiler cast base class rvalue reference to derived\ 56 class rvalue reference" 57 58gdb_test "print static_cast<A &&> (*b)" " = \\(A \\&\\&\\) @$hex: {a = 42}" \ 59 "static_cast to rvalue reference type" 60 61gdb_test "print reinterpret_cast<A &&> (*b)" \ 62 " = \\(A \\&\\&\\) @$hex: {a = 42}" \ 63 "reinterpret_cast to rvalue reference type" 64 65gdb_test "print dynamic_cast<Alpha &&> (derived)" \ 66 " = \\(Alpha \\&\\&\\) @$nonzero_hex: {.* = ${nonzero_hex}(\ 67 <vtable for Derived.*>)?}" \ 68 "dynamic_cast simple upcast to rvalue reference" 69 70gdb_test "print dynamic_cast<VirtuallyDerived &&> (*ad)" \ 71 "dynamic_cast failed" \ 72 "dynamic_cast to rvalue reference to non-existing base" 73