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