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