]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.cp/operator.exp
Automatic Copyright Year update after running gdb/copyright.py
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.cp / operator.exp
1 # Copyright 2008-2022 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 standard_testfile .cc
17
18 if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile} \
19 {debug c++ additional_flags=-Wno-unused-comparison}] } {
20 return -1
21 }
22
23 ############################################
24
25 if ![runto_main] then {
26 perror "couldn't run to breakpoint main"
27 continue
28 }
29
30 # Test global operator
31 gdb_test "p a == 1" "= 11" "global operator"
32 gdb_test "p a == 'a'" "= 12" "global operator overload"
33
34 # Test ADL operator
35 gdb_test "p bc == 1" "= 22" "ADL operator"
36 gdb_test "p bc == 'a'" "= 23" "ADL operator overload"
37 gdb_test "p B::BD::operator== (bc,'a')" "= 24" "fully qualified explicit operator call"
38
39 # Test operator imported from anonymous namespace
40 gdb_test "p d == 1" "= 33" "anonymous namespace operator"
41 gdb_test "p d == 'a'" "= 34" "anonymous namespace operator overload"
42 gdb_test "p d == 1.0f" "= 35" "anonymous namespace operator overload float"
43
44 # Test operator imported by using directive
45 gdb_test "p e == 1" "= 44" "imported operator"
46 gdb_test "p e == 'a'" "= 45" "imported operator overload"
47 gdb_test "p e == 1.0f" "= 46" "imported operator overload float"
48
49 # Test member operator
50 gdb_test "p g == 1" "= 55" "member operator"
51 gdb_test "p g == 'a'" "= 56" "member operator overload"
52
53 # Test that operators are not wrongly imported
54 # by import declarations and namespace aliases
55 gdb_test "p h == 1" "Cannot resolve function operator== to any overloaded instance" "namespace alias"
56 gdb_test "p j == 1" "Cannot resolve function operator== to any overloaded instance" "imported declaration"
57
58 # Test that indirectly imported operators work
59 gdb_test "p l == 1" "= 88"
60
61 # Test that we don't fall into an import loop
62 gdb_test {p x[0]} {No symbol "operator\[\]" in current context.}