1 # Tests of overloaded operators resolution.
2 # Copyright 1998-1999, 2002, 2004-2012 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"
26 if { [skip_stl_tests] } { continue }
28 # On SPU this test fails because the executable exceeds local storage size.
29 if { [istarget "spu*-*-*"] } {
33 set testfile "userdef"
34 set srcfile ${testfile}.cc
35 set binfile ${objdir}/${subdir}/${testfile}
37 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
45 gdb_reinitialize_dir $srcdir/$subdir
49 if ![runto_main] then {
50 perror "couldn't run to breakpoint"
54 gdb_test "break marker1" \
55 "Breakpoint .*${srcfile}.*"
58 "Break.* marker1(\\(\\)|) \\(\\) at .*:$decimal.*" \
61 gdb_test "up" " in main .*" "up from marker1"
63 gdb_test "print one + two" "\\\$\[0-9\]* = {x = 6, y = 8}"
65 # If GDB fails to restore the selected frame properly after the
66 # inferior function call above (see GDB PR 1155 for an explanation of
67 # why this might happen), all the subsequent tests will fail. We
68 # should detect report that failure, but let the marker call finish so
69 # that the rest of the tests can run undisturbed.
70 gdb_test_multiple "frame" "re-selected 'main' frame after inferior call" {
71 -re "#0 marker1.*$gdb_prompt $" {
72 setup_kfail "gdb/1155" s390-*-linux-gnu
73 fail "re-selected 'main' frame after inferior call"
74 gdb_test "finish" ".*main.*at .*userdef.cc:.*// marker1-returns-here.*" \
75 "finish call to marker1"
77 -re "#1 ($hex in )?main.*$gdb_prompt $" {
78 pass "re-selected 'main' frame after inferior call"
82 gdb_test "print one - two" "\\\$\[0-9\]* = {x = -2, y = -2}"
84 gdb_test "print one * two" "\\\$\[0-9\]* = {x = 8, y = 15}"
86 gdb_test "print one / two" "\\\$\[0-9\]* = {x = 0, y = 0}"
88 gdb_test "print one % two" "\\\$\[0-9\]* = {x = 2, y = 3}"
90 gdb_test "print one && two" "\\\$\[0-9\]* = 1\[\r\n\]"
92 gdb_test "print one || two" "\\\$\[0-9\]* = 1\[\r\n\]"
94 gdb_test "print one & two" "\\\$\[0-9\]* = {x = 0, y = 1}"
96 gdb_test "print one | two" "\\\$\[0-9\]* = {x = 6, y = 7}"
98 gdb_test "print one ^ two" "\\\$\[0-9\]* = {x = 6, y = 6}"
100 gdb_test "print one < two" "\\\$\[0-9\]* = 1\[\r\n\]"
102 gdb_test "print one <= two" "\\\$\[0-9\]* = 1\[\r\n\]"
104 gdb_test "print one > two" "\\\$\[0-9\]* = 0\[\r\n\]"
106 gdb_test "print one >= two" "\\\$\[0-9\]* = 0\[\r\n\]"
108 gdb_test "print one == two" "\\\$\[0-9\]* = 0\[\r\n\]"
109 gdb_test "print one.operator== (two)" "\\\$\[0-9\]* = 0\[\r\n\]"
111 gdb_test "print one != two" "\\\$\[0-9\]* = 1\[\r\n\]"
113 # Can't really check the output of this one without knowing
114 # target integer width. Make sure we don't try to call
115 # the iostreams operator instead, though.
116 gdb_test "print one << 31" "\\\$\[0-9\]* = {x = -?\[0-9\]*, y = -?\[0-9\]*}"
118 # Should be fine even on < 32-bit targets.
119 gdb_test "print one >> 31" "\\\$\[0-9\]* = {x = 0, y = 0}"
121 gdb_test "print !one" "\\\$\[0-9\]* = 0\[\r\n\]"
123 # Assumes 2's complement. So does everything...
124 gdb_test "print +one" "\\\$\[0-9\]* = {x = 2, y = 3}"
126 gdb_test "print ~one" "\\\$\[0-9\]* = {x = -3, y = -4}"
128 gdb_test "print -one" "\\\$\[0-9\]* = {x = -2, y = -3}"
130 gdb_test "print one++" "\\\$\[0-9\]* = {x = 2, y = 4}"
132 gdb_test "print ++one" "\\\$\[0-9\]* = {x = 3, y = 4}"
134 gdb_test "print one--" "\\\$\[0-9\]* = {x = 3, y = 3}"
136 gdb_test "print --one" "\\\$\[0-9\]* = {x = 2, y = 3}"
138 gdb_test "print one += 7" "\\\$\[0-9\]* = {x = 9, y = 10}"
140 gdb_test "print two = one" "\\\$\[0-9\]* = {x = 9, y = 10}"
142 # Check that GDB tolerates whitespace in operator names.
143 gdb_test "break A2::'operator+'" ".*Breakpoint $decimal at.*"
144 gdb_test "break A2::'operator +'" ".*Breakpoint $decimal at.*"
146 # Check that GDB handles operator* correctly.
147 gdb_test "print c" "\\\$\[0-9\]* = {m = {z = .*}}"
148 gdb_test "print *c" "\\\$\[0-9\]* = \\(Member &\\) @$hex: {z = .*}"
149 gdb_test "print &*c" "\\\$\[0-9\]* = \\(Member \\*\\) $hex"
150 gdb_test "ptype &*c" "type = (struct|class) Member {(\[\r\n \]+public:)?\[\r\n \]+int z;\[\r\n\].*} &\\*"
152 gdb_test "print operator== (mem1, mem2)" " = false"
153 gdb_test "print operator== (mem1, mem1)" " = true"