]>
Commit | Line | Data |
---|---|---|
d4f3574e | 1 | # Tests of overloaded operators resolution. |
b811d2c2 | 2 | # Copyright 1998-2020 Free Software Foundation, Inc. |
c906108c SS |
3 | |
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 | |
e22f8b7c | 6 | # the Free Software Foundation; either version 3 of the License, or |
c906108c | 7 | # (at your option) any later version. |
e22f8b7c | 8 | # |
c906108c SS |
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. | |
e22f8b7c | 13 | # |
c906108c | 14 | # You should have received a copy of the GNU General Public License |
e22f8b7c | 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
c906108c | 16 | |
c906108c SS |
17 | # written by Elena Zannoni (ezannoni@cygnus.com) |
18 | # | |
c906108c SS |
19 | # source file "userdef.cc" |
20 | # | |
21 | ||
759f0f0b | 22 | if { [skip_stl_tests] } { continue } |
c906108c | 23 | |
f5f3a911 | 24 | standard_testfile .cc |
c906108c | 25 | |
5b362f04 | 26 | if {[prepare_for_testing "failed to prepare" $testfile $srcfile {debug c++}]} { |
f5f3a911 | 27 | return -1 |
c906108c SS |
28 | } |
29 | ||
c906108c SS |
30 | if ![runto_main] then { |
31 | perror "couldn't run to breakpoint" | |
32 | continue | |
33 | } | |
34 | ||
f8d3bf8f MS |
35 | gdb_test "break marker1" \ |
36 | "Breakpoint .*${srcfile}.*" | |
c906108c | 37 | |
f8d3bf8f MS |
38 | gdb_test "cont" \ |
39 | "Break.* marker1(\\(\\)|) \\(\\) at .*:$decimal.*" \ | |
40 | "continue to marker1" | |
41 | ||
42 | gdb_test "up" " in main .*" "up from marker1" | |
c906108c | 43 | |
fb8acdcc DJ |
44 | gdb_test "print one + two" "\\\$\[0-9\]* = {x = 6, y = 8}" |
45 | ||
5624293a JB |
46 | # If GDB fails to restore the selected frame properly after the |
47 | # inferior function call above (see GDB PR 1155 for an explanation of | |
48 | # why this might happen), all the subsequent tests will fail. We | |
49 | # should detect report that failure, but let the marker call finish so | |
50 | # that the rest of the tests can run undisturbed. | |
51 | gdb_test_multiple "frame" "re-selected 'main' frame after inferior call" { | |
52 | -re "#0 marker1.*$gdb_prompt $" { | |
53 | setup_kfail "gdb/1155" s390-*-linux-gnu | |
54 | fail "re-selected 'main' frame after inferior call" | |
93201743 | 55 | gdb_test "finish" ".*main.*at .*userdef.cc:.*// marker1-returns-here.*" \ |
5624293a JB |
56 | "finish call to marker1" |
57 | } | |
58 | -re "#1 ($hex in )?main.*$gdb_prompt $" { | |
59 | pass "re-selected 'main' frame after inferior call" | |
60 | } | |
61 | } | |
62 | ||
fb8acdcc DJ |
63 | gdb_test "print one - two" "\\\$\[0-9\]* = {x = -2, y = -2}" |
64 | ||
65 | gdb_test "print one * two" "\\\$\[0-9\]* = {x = 8, y = 15}" | |
66 | ||
67 | gdb_test "print one / two" "\\\$\[0-9\]* = {x = 0, y = 0}" | |
68 | ||
69 | gdb_test "print one % two" "\\\$\[0-9\]* = {x = 2, y = 3}" | |
70 | ||
71 | gdb_test "print one && two" "\\\$\[0-9\]* = 1\[\r\n\]" | |
72 | ||
73 | gdb_test "print one || two" "\\\$\[0-9\]* = 1\[\r\n\]" | |
74 | ||
75 | gdb_test "print one & two" "\\\$\[0-9\]* = {x = 0, y = 1}" | |
76 | ||
77 | gdb_test "print one | two" "\\\$\[0-9\]* = {x = 6, y = 7}" | |
78 | ||
79 | gdb_test "print one ^ two" "\\\$\[0-9\]* = {x = 6, y = 6}" | |
80 | ||
81 | gdb_test "print one < two" "\\\$\[0-9\]* = 1\[\r\n\]" | |
82 | ||
83 | gdb_test "print one <= two" "\\\$\[0-9\]* = 1\[\r\n\]" | |
84 | ||
85 | gdb_test "print one > two" "\\\$\[0-9\]* = 0\[\r\n\]" | |
86 | ||
87 | gdb_test "print one >= two" "\\\$\[0-9\]* = 0\[\r\n\]" | |
88 | ||
89 | gdb_test "print one == two" "\\\$\[0-9\]* = 0\[\r\n\]" | |
6e31430b | 90 | gdb_test "print one.operator== (two)" "\\\$\[0-9\]* = 0\[\r\n\]" |
fb8acdcc DJ |
91 | |
92 | gdb_test "print one != two" "\\\$\[0-9\]* = 1\[\r\n\]" | |
93 | ||
94 | # Can't really check the output of this one without knowing | |
95 | # target integer width. Make sure we don't try to call | |
96 | # the iostreams operator instead, though. | |
97 | gdb_test "print one << 31" "\\\$\[0-9\]* = {x = -?\[0-9\]*, y = -?\[0-9\]*}" | |
98 | ||
99 | # Should be fine even on < 32-bit targets. | |
100 | gdb_test "print one >> 31" "\\\$\[0-9\]* = {x = 0, y = 0}" | |
101 | ||
102 | gdb_test "print !one" "\\\$\[0-9\]* = 0\[\r\n\]" | |
103 | ||
104 | # Assumes 2's complement. So does everything... | |
36e9969c NS |
105 | gdb_test "print +one" "\\\$\[0-9\]* = {x = 2, y = 3}" |
106 | ||
fb8acdcc DJ |
107 | gdb_test "print ~one" "\\\$\[0-9\]* = {x = -3, y = -4}" |
108 | ||
109 | gdb_test "print -one" "\\\$\[0-9\]* = {x = -2, y = -3}" | |
110 | ||
111 | gdb_test "print one++" "\\\$\[0-9\]* = {x = 2, y = 4}" | |
112 | ||
113 | gdb_test "print ++one" "\\\$\[0-9\]* = {x = 3, y = 4}" | |
114 | ||
115 | gdb_test "print one--" "\\\$\[0-9\]* = {x = 3, y = 3}" | |
116 | ||
117 | gdb_test "print --one" "\\\$\[0-9\]* = {x = 2, y = 3}" | |
118 | ||
119 | gdb_test "print one += 7" "\\\$\[0-9\]* = {x = 9, y = 10}" | |
120 | ||
121 | gdb_test "print two = one" "\\\$\[0-9\]* = {x = 9, y = 10}" | |
c906108c | 122 | |
13b57657 | 123 | # Check that GDB tolerates whitespace in operator names. |
40e084e1 KS |
124 | gdb_test "break A2::operator+" ".*Breakpoint $decimal at.*" |
125 | gdb_test "break A2::operator +" ".*Breakpoint $decimal at.*" | |
13b57657 | 126 | |
ab5c9f60 DJ |
127 | # Check that GDB handles operator* correctly. |
128 | gdb_test "print c" "\\\$\[0-9\]* = {m = {z = .*}}" | |
129 | gdb_test "print *c" "\\\$\[0-9\]* = \\(Member &\\) @$hex: {z = .*}" | |
130 | gdb_test "print &*c" "\\\$\[0-9\]* = \\(Member \\*\\) $hex" | |
4819b3f8 | 131 | gdb_test "ptype &*c" "type = (struct|class) Member {(\[\r\n \]+public:)?\[\r\n \]+int z;\[\r\n\].*} \\*" |
ab5c9f60 | 132 | |
6e31430b TT |
133 | gdb_test "print operator== (mem1, mem2)" " = false" |
134 | gdb_test "print operator== (mem1, mem1)" " = true" | |
135 | ||
c906108c SS |
136 | gdb_exit |
137 | return 0 |