1303241Sdim# Tests of overloaded operators resolution. 2303241Sdim# Copyright 1998-2023 Free Software Foundation, Inc. 3353358Sdim 4353358Sdim# This program is free software; you can redistribute it and/or modify 5353358Sdim# it under the terms of the GNU General Public License as published by 6303241Sdim# the Free Software Foundation; either version 3 of the License, or 7303241Sdim# (at your option) any later version. 8303241Sdim# 9303241Sdim# This program is distributed in the hope that it will be useful, 10303241Sdim# but WITHOUT ANY WARRANTY; without even the implied warranty of 11303241Sdim# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12303241Sdim# GNU General Public License for more details. 13303241Sdim# 14303241Sdim# You should have received a copy of the GNU General Public License 15303241Sdim# along with this program. If not, see <http://www.gnu.org/licenses/>. 16344779Sdim 17344779Sdim# written by Elena Zannoni (ezannoni@cygnus.com) 18314564Sdim# 19303241Sdim# source file "userdef.cc" 20303241Sdim# 21303241Sdim 22303241Sdimif { [skip_stl_tests] } { return } 23341825Sdim 24303241Sdimstandard_testfile .cc 25314564Sdim 26303241Sdimif {[prepare_for_testing "failed to prepare" $testfile $srcfile {debug c++}]} { 27303241Sdim return -1 28341825Sdim} 29303241Sdim 30314564Sdimif {![runto_main]} { 31314564Sdim return 32344779Sdim} 33344779Sdim 34303241Sdimgdb_test "break marker1" \ 35303241Sdim "Breakpoint .*${srcfile}.*" 36344779Sdim 37344779Sdimgdb_test "cont" \ 38303241Sdim "Break.* marker1(\\(\\)|) \\(\\) at .*:$decimal.*" \ 39344779Sdim "continue to marker1" 40341825Sdim 41341825Sdimgdb_test "up" " in main .*" "up from marker1" 42303241Sdim 43314564Sdimgdb_test "print one + two" "\\\$\[0-9\]* = {x = 6, y = 8}" 44303241Sdim 45314564Sdim# If GDB fails to restore the selected frame properly after the 46314564Sdim# inferior function call above (see GDB PR 1155 for an explanation of 47303241Sdim# why this might happen), all the subsequent tests will fail. We 48314564Sdim# should detect report that failure, but let the marker call finish so 49344779Sdim# that the rest of the tests can run undisturbed. 50303241Sdimgdb_test_multiple "frame" "re-selected 'main' frame after inferior call" { 51344779Sdim -re "#0 marker1.*$gdb_prompt $" { 52344779Sdim setup_kfail "gdb/1155" s390-*-linux-gnu 53344779Sdim fail "re-selected 'main' frame after inferior call" 54344779Sdim gdb_test "finish" ".*main.*at .*userdef.cc:.*// marker1-returns-here.*" \ 55344779Sdim "finish call to marker1" 56344779Sdim } 57344779Sdim -re "#1 ($hex in )?main.*$gdb_prompt $" { 58344779Sdim pass "re-selected 'main' frame after inferior call" 59344779Sdim } 60344779Sdim} 61344779Sdim 62344779Sdimgdb_test "print one - two" "\\\$\[0-9\]* = {x = -2, y = -2}" 63344779Sdim 64344779Sdimgdb_test "print one * two" "\\\$\[0-9\]* = {x = 8, y = 15}" 65344779Sdim 66344779Sdimgdb_test "print one / two" "\\\$\[0-9\]* = {x = 0, y = 0}" 67303241Sdim 68344779Sdimgdb_test "print one % two" "\\\$\[0-9\]* = {x = 2, y = 3}" 69344779Sdim 70344779Sdimgdb_test "print one && two" "\\\$\[0-9\]* = 1\[\r\n\]" 71344779Sdim 72344779Sdimgdb_test "print one || two" "\\\$\[0-9\]* = 1\[\r\n\]" 73344779Sdim 74344779Sdimgdb_test "print one & two" "\\\$\[0-9\]* = {x = 0, y = 1}" 75344779Sdim 76344779Sdimgdb_test "print one | two" "\\\$\[0-9\]* = {x = 6, y = 7}" 77344779Sdim 78344779Sdimgdb_test "print one ^ two" "\\\$\[0-9\]* = {x = 6, y = 6}" 79344779Sdim 80344779Sdimgdb_test "print one < two" "\\\$\[0-9\]* = 1\[\r\n\]" 81344779Sdim 82344779Sdimgdb_test "print one <= two" "\\\$\[0-9\]* = 1\[\r\n\]" 83314564Sdim 84344779Sdimgdb_test "print one > two" "\\\$\[0-9\]* = 0\[\r\n\]" 85344779Sdim 86344779Sdimgdb_test "print one >= two" "\\\$\[0-9\]* = 0\[\r\n\]" 87344779Sdim 88344779Sdimgdb_test "print one == two" "\\\$\[0-9\]* = 0\[\r\n\]" 89344779Sdimgdb_test "print one.operator== (two)" "\\\$\[0-9\]* = 0\[\r\n\]" 90344779Sdim 91344779Sdimgdb_test "print one != two" "\\\$\[0-9\]* = 1\[\r\n\]" 92344779Sdim 93344779Sdim# Can't really check the output of this one without knowing 94344779Sdim# target integer width. Make sure we don't try to call 95344779Sdim# the iostreams operator instead, though. 96344779Sdimgdb_test "print one << 31" "\\\$\[0-9\]* = {x = -?\[0-9\]*, y = -?\[0-9\]*}" 97344779Sdim 98344779Sdim# Should be fine even on < 32-bit targets. 99344779Sdimgdb_test "print one >> 31" "\\\$\[0-9\]* = {x = 0, y = 0}" 100344779Sdim 101344779Sdimgdb_test "print !one" "\\\$\[0-9\]* = 0\[\r\n\]" 102344779Sdim 103344779Sdim# Assumes 2's complement. So does everything... 104344779Sdimgdb_test "print +one" "\\\$\[0-9\]* = {x = 2, y = 3}" 105303241Sdim 106314564Sdimgdb_test "print ~one" "\\\$\[0-9\]* = {x = -3, y = -4}" 107314564Sdim 108344779Sdimgdb_test "print -one" "\\\$\[0-9\]* = {x = -2, y = -3}" 109344779Sdim 110344779Sdimgdb_test "print one++" "\\\$\[0-9\]* = {x = 2, y = 4}" 111344779Sdim 112344779Sdimgdb_test "print ++one" "\\\$\[0-9\]* = {x = 3, y = 4}" 113344779Sdim 114303241Sdimgdb_test "print one--" "\\\$\[0-9\]* = {x = 3, y = 3}" 115303241Sdim 116341825Sdimgdb_test "print --one" "\\\$\[0-9\]* = {x = 2, y = 3}" 117 118gdb_test "print one += 7" "\\\$\[0-9\]* = {x = 9, y = 10}" 119 120gdb_test "print two = one" "\\\$\[0-9\]* = {x = 9, y = 10}" 121 122# Check that GDB tolerates whitespace in operator names. 123gdb_test "break A2::operator+" ".*Breakpoint $decimal at.*" 124gdb_test "break A2::operator +" ".*Breakpoint $decimal at.*" 125 126# Check that GDB handles operator* correctly. 127gdb_test "print c" "\\\$\[0-9\]* = {m = {z = .*}}" 128gdb_test "print *c" "\\\$\[0-9\]* = \\(Member &\\) @$hex: {z = .*}" 129gdb_test "print &*c" "\\\$\[0-9\]* = \\(Member \\*\\) $hex" 130gdb_test "ptype &*c" "type = (struct|class) Member {(\[\r\n \]+public:)?\[\r\n \]+int z;\[\r\n\].*} \\*" 131 132gdb_test "print operator== (mem1, mem2)" " = false" 133gdb_test "print operator== (mem1, mem1)" " = true" 134 135gdb_exit 136return 0 137