1# Copyright 2021-2023 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
23if { [prepare_for_testing "failed to prepare" $testfile $srcfile] } {
24    return -1
25}
26
27if {![runto_main]} {
28    return 0
29}
30
31gdb_breakpoint [gdb_get_line_number "Break here"]
32gdb_continue_to_breakpoint "Break here"
33
34set result 123
35foreach_with_prefix lang { c++ c } {
36    foreach_with_prefix overload_resolution { on off } {
37	gdb_test_no_output "set overload-resolution ${overload_resolution}"
38	gdb_test "set language ${lang}"
39
40	gdb_test "print foo.func (b, f)" " = ${result}"
41	incr result
42
43	set result [expr $result + 3]
44	gdb_test "print foo += b" \
45	    " = \\((?:struct )?foo_type &\\) @${hex}: \\\{var = ${result}\\\}"
46
47	gdb_test "print foo.static_method (f, b)" " = 4"
48	gdb_test "print foo_type::static_method (f, b)" " = 4"
49    }
50}
51