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