1 # Copyright 2002-2019 Free Software Foundation, Inc.
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.
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.
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/>.
16 # This file is part of the gdb testsuite
18 # C++11 rvalue reference type casting tests, based on gdb.cp/casts.exp.
20 if {[skip_cplus_tests]} { continue }
24 if {[get_compiler_info "c++"]} {
28 if {[prepare_for_testing $testfile.exp $testfile $srcfile \
29 {debug c++ additional_flags="-std=gnu++11"}]} {
34 untested "couldn't run to main"
38 # Prevent symbol on address 0x0 being printed.
39 gdb_test_no_output "set print symbol off"
41 set line [gdb_get_line_number {rvalue-ref-casts.exp: 1}]
42 gdb_test "break $line" "Breakpoint.*at.* file .*$srcfile, line $line\\." \
43 "break at test location"
45 gdb_test "continue" "Breakpoint .* at .*$srcfile:$line.*"
48 gdb_test "print (A &&) br" ".* = .A &&.* {a = 42}" \
49 "cast derived class rvalue reference to base class rvalue reference"
52 gdb_test "print (B &&) ar" ".* = .B.* {<A> = {a = 42}, b = 1729}" \
53 "cast base class rvalue reference to derived class rvalue reference"
55 # Check compiler casting
57 set nonzero_hex "0x\[0-9A-Fa-f\]\[0-9A-Fa-f\]+"
59 gdb_test "print br" ".* = .B.* {<A> = {a = 42}, b = 1729}" \
60 "let compiler cast base class rvalue reference to derived\
61 class rvalue reference"
63 gdb_test "print static_cast<A &&> (*b)" " = \\(A \\&\\&\\) @$hex: {a = 42}" \
64 "static_cast to rvalue reference type"
66 gdb_test "print reinterpret_cast<A &&> (*b)" \
67 " = \\(A \\&\\&\\) @$hex: {a = 42}" \
68 "reinterpret_cast to rvalue reference type"
70 gdb_test "print dynamic_cast<Alpha &&> (derived)" \
71 " = \\(Alpha \\&\\&\\) @$nonzero_hex: {.* = ${nonzero_hex}(\
72 <vtable for Derived.*>)?}" \
73 "dynamic_cast simple upcast to rvalue reference"
75 gdb_test "print dynamic_cast<VirtuallyDerived &&> (*ad)" \
76 "dynamic_cast failed" \
77 "dynamic_cast to rvalue reference to non-existing base"