]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.cp/rvalue-ref-casts.exp
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.cp / rvalue-ref-casts.exp
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
20 if {[skip_cplus_tests]} { continue }
21
22 standard_testfile .cc
23
24 if {[prepare_for_testing $testfile.exp $testfile $srcfile \
25 {debug c++ additional_flags="-std=gnu++11"}]} {
26 return -1
27 }
28
29 if {![runto_main]} {
30 return -1
31 }
32
33 # Prevent symbol on address 0x0 being printed.
34 gdb_test_no_output "set print symbol off"
35
36 set line [gdb_get_line_number {rvalue-ref-casts.exp: 1}]
37 gdb_test "break $line" "Breakpoint.*at.* file .*$srcfile, line $line\\." \
38 "break at test location"
39
40 gdb_test "continue" "Breakpoint .* at .*$srcfile:$line.*"
41
42 # Check upcasting.
43 gdb_test "print (A &&) br" ".* = .A &&.* {a = 42}" \
44 "cast derived class rvalue reference to base class rvalue reference"
45
46 # Check downcasting.
47 gdb_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
52 set nonzero_hex "0x\[0-9A-Fa-f\]\[0-9A-Fa-f\]+"
53
54 gdb_test "print br" ".* = .B.* {<A> = {a = 42}, b = 1729}" \
55 "let compiler cast base class rvalue reference to derived\
56 class rvalue reference"
57
58 gdb_test "print static_cast<A &&> (*b)" " = \\(A \\&\\&\\) @$hex: {a = 42}" \
59 "static_cast to rvalue reference type"
60
61 gdb_test "print reinterpret_cast<A &&> (*b)" \
62 " = \\(A \\&\\&\\) @$hex: {a = 42}" \
63 "reinterpret_cast to rvalue reference type"
64
65 gdb_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
70 gdb_test "print dynamic_cast<VirtuallyDerived &&> (*ad)" \
71 "dynamic_cast failed" \
72 "dynamic_cast to rvalue reference to non-existing base"