rvalue-ref-casts.exp revision 1.1.1.2
1# Copyright 2002-2019 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 {[get_compiler_info "c++"]} { 25 return -1 26} 27 28if {[prepare_for_testing $testfile.exp $testfile $srcfile \ 29 {debug c++ additional_flags="-std=gnu++11"}]} { 30 return -1 31} 32 33if {![runto_main]} { 34 untested "couldn't run to main" 35 return -1 36} 37 38# Prevent symbol on address 0x0 being printed. 39gdb_test_no_output "set print symbol off" 40 41set line [gdb_get_line_number {rvalue-ref-casts.exp: 1}] 42gdb_test "break $line" "Breakpoint.*at.* file .*$srcfile, line $line\\." \ 43 "break at test location" 44 45gdb_test "continue" "Breakpoint .* at .*$srcfile:$line.*" 46 47# Check upcasting. 48gdb_test "print (A &&) br" ".* = .A &&.* {a = 42}" \ 49 "cast derived class rvalue reference to base class rvalue reference" 50 51# Check downcasting. 52gdb_test "print (B &&) ar" ".* = .B.* {<A> = {a = 42}, b = 1729}" \ 53 "cast base class rvalue reference to derived class rvalue reference" 54 55# Check compiler casting 56 57set nonzero_hex "0x\[0-9A-Fa-f\]\[0-9A-Fa-f\]+" 58 59gdb_test "print br" ".* = .B.* {<A> = {a = 42}, b = 1729}" \ 60 "let compiler cast base class rvalue reference to derived\ 61 class rvalue reference" 62 63gdb_test "print static_cast<A &&> (*b)" " = \\(A \\&\\&\\) @$hex: {a = 42}" \ 64 "static_cast to rvalue reference type" 65 66gdb_test "print reinterpret_cast<A &&> (*b)" \ 67 " = \\(A \\&\\&\\) @$hex: {a = 42}" \ 68 "reinterpret_cast to rvalue reference type" 69 70gdb_test "print dynamic_cast<Alpha &&> (derived)" \ 71 " = \\(Alpha \\&\\&\\) @$nonzero_hex: {.* = ${nonzero_hex}(\ 72 <vtable for Derived.*>)?}" \ 73 "dynamic_cast simple upcast to rvalue reference" 74 75gdb_test "print dynamic_cast<VirtuallyDerived &&> (*ad)" \ 76 "dynamic_cast failed" \ 77 "dynamic_cast to rvalue reference to non-existing base" 78