Update copyright year range in header of all files managed by GDB
[binutils-gdb.git] / gdb / testsuite / gdb.cp / userdef.exp
blobfbe1bc7d3f9462451995f27734b1481e4744a6b5
1 # Tests of overloaded operators resolution.
2 # Copyright 1998-2023 Free Software Foundation, Inc.
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 # written by Elena Zannoni (ezannoni@cygnus.com)
19 # source file "userdef.cc"
22 if { [skip_stl_tests] } { return }
24 standard_testfile .cc
26 if {[prepare_for_testing "failed to prepare" $testfile $srcfile {debug c++}]} {
27     return -1
30 if {![runto_main]} {
31     return
34 gdb_test "break marker1" \
35     "Breakpoint .*${srcfile}.*" 
37 gdb_test "cont" \
38     "Break.* marker1(\\(\\)|) \\(\\) at .*:$decimal.*" \
39     "continue to marker1"
41 gdb_test "up" " in main .*" "up from marker1"
43 gdb_test "print one + two" "\\\$\[0-9\]* = {x = 6, y = 8}"
45 # If GDB fails to restore the selected frame properly after the
46 # inferior function call above (see GDB PR 1155 for an explanation of
47 # why this might happen), all the subsequent tests will fail.  We
48 # should detect report that failure, but let the marker call finish so
49 # that the rest of the tests can run undisturbed.
50 gdb_test_multiple "frame" "re-selected 'main' frame after inferior call" {
51     -re "#0  marker1.*$gdb_prompt $" {
52         setup_kfail "gdb/1155" s390-*-linux-gnu
53         fail "re-selected 'main' frame after inferior call"
54         gdb_test "finish" ".*main.*at .*userdef.cc:.*// marker1-returns-here.*" \
55                 "finish call to marker1"
56     }
57     -re "#1  ($hex in )?main.*$gdb_prompt $" {
58         pass "re-selected 'main' frame after inferior call"
59     }
61         
62 gdb_test "print one - two" "\\\$\[0-9\]* = {x = -2, y = -2}"
64 gdb_test "print one * two" "\\\$\[0-9\]* = {x = 8, y = 15}"
66 gdb_test "print one / two" "\\\$\[0-9\]* = {x = 0, y = 0}"
68 gdb_test "print one % two" "\\\$\[0-9\]* = {x = 2, y = 3}"
70 gdb_test "print one && two" "\\\$\[0-9\]* = 1\[\r\n\]"
72 gdb_test "print one || two" "\\\$\[0-9\]* = 1\[\r\n\]"
74 gdb_test "print one & two" "\\\$\[0-9\]* = {x = 0, y = 1}"
76 gdb_test "print one | two" "\\\$\[0-9\]* = {x = 6, y = 7}"
78 gdb_test "print one ^ two" "\\\$\[0-9\]* = {x = 6, y = 6}"
80 gdb_test "print one < two" "\\\$\[0-9\]* = 1\[\r\n\]"
82 gdb_test "print one <= two" "\\\$\[0-9\]* = 1\[\r\n\]"
84 gdb_test "print one > two" "\\\$\[0-9\]* = 0\[\r\n\]"
86 gdb_test "print one >= two" "\\\$\[0-9\]* = 0\[\r\n\]"
88 gdb_test "print one == two" "\\\$\[0-9\]* = 0\[\r\n\]"
89 gdb_test "print one.operator== (two)" "\\\$\[0-9\]* = 0\[\r\n\]"
91 gdb_test "print one != two" "\\\$\[0-9\]* = 1\[\r\n\]"
93 # Can't really check the output of this one without knowing
94 # target integer width.  Make sure we don't try to call
95 # the iostreams operator instead, though.
96 gdb_test "print one << 31" "\\\$\[0-9\]* = {x = -?\[0-9\]*, y = -?\[0-9\]*}"
98 # Should be fine even on < 32-bit targets.
99 gdb_test "print one >> 31" "\\\$\[0-9\]* = {x = 0, y = 0}"
101 gdb_test "print !one" "\\\$\[0-9\]* = 0\[\r\n\]"
103 # Assumes 2's complement.  So does everything...
104 gdb_test "print +one" "\\\$\[0-9\]* = {x = 2, y = 3}"
106 gdb_test "print ~one" "\\\$\[0-9\]* = {x = -3, y = -4}"
108 gdb_test "print -one" "\\\$\[0-9\]* = {x = -2, y = -3}"
110 gdb_test "print one++" "\\\$\[0-9\]* = {x = 2, y = 4}"
112 gdb_test "print ++one" "\\\$\[0-9\]* = {x = 3, y = 4}"
114 gdb_test "print one--" "\\\$\[0-9\]* = {x = 3, y = 3}"
116 gdb_test "print --one" "\\\$\[0-9\]* = {x = 2, y = 3}"
118 gdb_test "print one += 7" "\\\$\[0-9\]* = {x = 9, y = 10}"
120 gdb_test "print two = one" "\\\$\[0-9\]* = {x = 9, y = 10}"
122 # Check that GDB tolerates whitespace in operator names.
123 gdb_test "break A2::operator+" ".*Breakpoint $decimal at.*"
124 gdb_test "break A2::operator +" ".*Breakpoint $decimal at.*"
126 # Check that GDB handles operator* correctly.
127 gdb_test "print c" "\\\$\[0-9\]* = {m = {z = .*}}"
128 gdb_test "print *c" "\\\$\[0-9\]* = \\(Member &\\) @$hex: {z = .*}"
129 gdb_test "print &*c" "\\\$\[0-9\]* = \\(Member \\*\\) $hex"
130 gdb_test "ptype &*c" "type = (struct|class) Member {(\[\r\n \]+public:)?\[\r\n \]+int z;\[\r\n\].*} \\*"
132 gdb_test "print operator== (mem1, mem2)" " = false"
133 gdb_test "print operator== (mem1, mem1)" " = true"
135 gdb_exit
136 return 0