]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.cp/operator.exp
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.cp / operator.exp
1 # Copyright 2008-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 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]} {
26 return
27 }
28
29 # Test global operator
30 gdb_test "p a == 1" "= 11" "global operator"
31 gdb_test "p a == 'a'" "= 12" "global operator overload"
32
33 # Test ADL operator
34 gdb_test "p bc == 1" "= 22" "ADL operator"
35 gdb_test "p bc == 'a'" "= 23" "ADL operator overload"
36 gdb_test "p B::BD::operator== (bc,'a')" "= 24" "fully qualified explicit operator call"
37
38 # Test operator imported from anonymous namespace
39 gdb_test "p d == 1" "= 33" "anonymous namespace operator"
40 gdb_test "p d == 'a'" "= 34" "anonymous namespace operator overload"
41 gdb_test "p d == 1.0f" "= 35" "anonymous namespace operator overload float"
42
43 # Test operator imported by using directive
44 gdb_test "p e == 1" "= 44" "imported operator"
45 gdb_test "p e == 'a'" "= 45" "imported operator overload"
46 gdb_test "p e == 1.0f" "= 46" "imported operator overload float"
47
48 # Test member operator
49 gdb_test "p g == 1" "= 55" "member operator"
50 gdb_test "p g == 'a'" "= 56" "member operator overload"
51
52 # Test that operators are not wrongly imported
53 # by import declarations and namespace aliases
54 gdb_test "p h == 1" "Cannot resolve function operator== to any overloaded instance" "namespace alias"
55 gdb_test "p j == 1" "Cannot resolve function operator== to any overloaded instance" "imported declaration"
56
57 # Test that indirectly imported operators work
58 gdb_test "p l == 1" "= 88"
59
60 # Test that we don't fall into an import loop
61 gdb_test {p x[0]} {No symbol "operator\[\]" in current context.}