xref: /netbsd-src/external/gpl3/gdb/dist/gdb/testsuite/gdb.cp/method-call-in-c.exp (revision 22ebeae4b2252475e0ebe332f69734639cb946ea)
1# Copyright 2021-2024 Free Software Foundation, Inc.
2
3# This program is free software; you can redistribute it and/or modify
4# it under the terms of the GNU General Public License as published by
5# the Free Software Foundation; either version 3 of the License, or
6# (at your option) any later version.
7#
8# This program is distributed in the hope that it will be useful,
9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11# GNU General Public License for more details.
12#
13# You should have received a copy of the GNU General Public License
14# along with this program.  If not, see <http://www.gnu.org/licenses/>.
15
16# Ensure that calling a member function works correctly even when the
17# language is forced to 'C' (this should be fine, so long at no
18# overload resolution is required), or when overload-resolution is
19# off.
20
21standard_testfile .cc
22
23set opts {}
24lappend opts debug
25lappend opts additional_flags=-std=c++11
26
27if { [prepare_for_testing "failed to prepare" $testfile $srcfile $opts] } {
28    return -1
29}
30
31if {![runto_main]} {
32    return 0
33}
34
35gdb_breakpoint [gdb_get_line_number "Break here"]
36gdb_continue_to_breakpoint "Break here"
37
38set result 123
39foreach_with_prefix lang { c++ c } {
40    foreach_with_prefix overload_resolution { on off } {
41	gdb_test_no_output "set overload-resolution ${overload_resolution}"
42	gdb_test "set language ${lang}"
43
44	gdb_test "print foo.func (b, f)" " = ${result}"
45	incr result
46
47	set result [expr $result + 3]
48	gdb_test "print foo += b" \
49	    " = \\((?:struct )?foo_type &\\) @${hex}: \\\{var = ${result}\\\}"
50
51	gdb_test "print foo.static_method (f, b)" " = 4"
52	gdb_test "print foo_type::static_method (f, b)" " = 4"
53    }
54}
55