1 # Copyright 2008-2024 Free Software Foundation, Inc.
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.
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.
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/>.
21 lappend opts additional_flags=-Wno-unused-comparison
22 lappend opts additional_flags=-std=c++11
24 if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile} $opts] } {
28 ############################################
34 # Test that koenig lookup finds correct function
35 gdb_test "p first(c)" "= 11"
37 # Change the number of parameters and position of
38 # the qualifying parameter
39 gdb_test "p second(0,0,c,0,0)" "= 33"
41 # Test evaluating function under EVAL_SKIP
42 gdb_test "p true || second(0,0,c,0,0)" "= true"
44 # Test the name "entry" being used for `variablename@entry' entry values.
45 gdb_test "p entry (c)" " = 44"
47 # Test that koenig lookup finds correct function
48 # even if it is overloaded
49 gdb_test "p first(0,c)" "= 22"
51 # Test that koenig lookup finds correct function
52 # when the argument is an expression
53 gdb_test "p first(b.c)" "= 11"
55 # test that resolutions can be made across namespaces
56 gdb_test "p foo(eo)" "= 1"
57 gdb_test "p foo(eo, eo)" "= 2"
58 gdb_test "p foo(eo, eo, 1)" "= 3"
59 gdb_test "p foo(fo, eo)" "= 4"
60 gdb_test "p foo(1 ,fo, eo)" "= 5"
61 gdb_test "p foo(go, fo, eo)" "= 6"
63 #test that gdb fails gracefully
64 gdb_test "p fake(eo)" "No symbol \"fake\" in current context."
65 gdb_test "p foo (fake)" "No symbol \"fake\" in current context."
67 #test that namespaces of base classes are searched
68 gdb_test "p foo(io)" "= 7"
69 gdb_test "p foo(ix)" "Cannot resolve function foo to any overloaded instance"
72 gdb_test "p foo(ju)" "= 8"
73 gdb_test "p foo(js)" "= 9"
74 gdb_test "p foo(je)" "= 10"
76 #test for class members
78 gdb_test "p foo(jab)" "= 11"
80 gdb_test "p foo(jap)" "= 12"
81 gdb_test "p foo(japp)" "= 13"
82 gdb_test "p foo(jca)" "= 14"
84 #test overload resolution
85 gdb_test "p foo(ko,1)" "= 15"
86 gdb_test "p foo(ko,1.0f)" "= 16"
88 gdb_test "p bar(ko,1)" "= -1"
90 #test lookup of objects belonging to nested namespaces
91 gdb_test "p foo(labo)" "= 17"
93 #test koenig found function do not compete with qualified
95 gdb_test "p ma.foo('a')" "= 18"
96 gdb_test "p foo(ma,'a')" "= 19"
97 gdb_test "p M::N::foo(ma,'a')" "= 20"
98 gdb_test "p M::FAKE::foo(ma,'a')" "No type \"FAKE\" within class or namespace \"M\"."
99 gdb_test "p M::N::fake(ma,'a')" "No symbol \"fake\" in namespace \"M::N\"."
101 gdb_test "p M::bar('a')" "= 21"
102 gdb_test "p M::N::bar('a')" "= 22"
104 #test that lookup supports typedef
105 gdb_test "p foo(ttoa, 'a')" "= 23"
107 #test that lookup is not thwarted by anonymous types
108 gdb_test "p foo (p_union)" \
109 "Cannot resolve function foo to any overloaded instance"
111 # test lookup of namespace user-defined operators
112 # and overload resolution:
115 gdb_test "p q == 5" "= 24"
116 gdb_test "p q == 5.0f" "= 25"
119 gdb_test "p q != 5" "= 27"
120 gdb_test "p q != 5.0f" "= 28"
122 # across namespace and class
123 gdb_test "p q + 5.0f" "= 26"
124 gdb_test "p q + 5" "= 29"
126 # some unary operators for good measure
127 # Cannot resolve function operator++ to any overloaded instance
128 gdb_test "p ++q" "= 30"
130 # Test that koening lookup does not affect
131 # member variable lookup.
132 gdb_test "p r.rfoo()" "= 31"
134 # Do the same from inside class R.
135 gdb_breakpoint [gdb_get_line_number "marker1"]
136 gdb_continue_to_breakpoint "marker1"
138 gdb_test "p rfoo()" "= 31"
139 gdb_test "p this->rfoo()" "= 31"