]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.cp/impl-this.exp
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.cp / impl-this.exp
CommitLineData
213516ef 1# Copyright 2013-2023 Free Software Foundation, Inc.
f7e3ecae
KS
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# This file is part of the gdb testsuite
17
18# Test expressions which assume an implicit "this" with a qualified
19# name.
20
cdd42066 21if {[skip_cplus_tests]} { return }
f7e3ecae
KS
22
23standard_testfile .cc
24
5b362f04 25if {[prepare_for_testing "failed to prepare" $testfile $srcfile {debug c++}]} {
f7e3ecae
KS
26 return -1
27}
28
2820f08f
BL
29set gcc_used [test_compiler_info gcc-*-*]
30
f7e3ecae
KS
31# First test expressions when there is no context.
32with_test_prefix "before run" {
33 gdb_test "print i" "No symbol \"i\" in current context."
34 gdb_test "print D::i" "Cannot reference non-static field \"i\""
35 gdb_test "print D::B<int>::i" "Cannot reference non-static field \"i\""
36 gdb_test "print B<int>::i" "Cannot reference non-static field \"i\""
37 gdb_test "print D::C::i" "Cannot reference non-static field \"i\""
38 gdb_test "print C::i" "Cannot reference non-static field \"i\""
39 gdb_test "print D::B<int>::A<int>::i" \
40 "Cannot reference non-static field \"i\""
41 gdb_test "print B<int>::A<int>::i" "Cannot reference non-static field \"i\""
42 gdb_test "print A<int>::i" "Cannot reference non-static field \"i\""
43 gdb_test "print D::C::A<int>::i" "Cannot reference non-static field \"i\""
44 gdb_test "print C::A<int>::i" "Cannot reference non-static field \"i\""
45 gdb_test "print D::x" "Cannot reference non-static field \"x\""
46 gdb_test "print x" "No symbol \"x\" in current context."
47 gdb_test "print D::C::c" "Cannot reference non-static field \"c\""
48 gdb_test "print C::c" "Cannot reference non-static field \"c\""
49 gdb_test "print c" "No symbol \"c\" in current context."
50 gdb_test "print D::A<int>::i" "Cannot reference non-static field \"i\""
51}
52
53# Run to D::f.
54if {![runto_main]} {
cdd42066 55 return
f7e3ecae
KS
56}
57
58gdb_breakpoint "D::f"
59gdb_continue_to_breakpoint "continue to D::f"
60
61# Now test valid expressions in the class hierarchy for D.
62with_test_prefix "at D::f (valid expressions)" {
63 gdb_test "print i" "= 4"
64 gdb_test "print D::i" "= 4"
65 gdb_test "print D::B<int>::i" "= 2"
66 gdb_test "print B<int>::i" "= 2"
2820f08f
BL
67
68 if {$gcc_used} {
69 setup_xfail *-*-* gcc/60833
70 }
71 gdb_test "print D::Bint::i" "= 2"
72
f7e3ecae
KS
73 gdb_test "print Bint::i" "= 2"
74 gdb_test "print D::C::i" "= 3"
75 gdb_test "print C::i" "= 3"
76 gdb_test "print D::B<int>::A<int>::i" "= 1"
77 gdb_test "print B<int>::A<int>::i" "= 1"
2820f08f
BL
78
79 if {$gcc_used} {
80 setup_xfail *-*-* gcc/60833
81 }
82 gdb_test "print D::Bint::A<int>::i" "= 1"
83
f7e3ecae
KS
84 gdb_test "print Bint::A<int>::i" "= 1"
85 gdb_test "print A<int>::i" "= 1"
86 gdb_test "print D::C::A<int>::i" "= 1"
87 gdb_test "print C::A<int>::i" "= 1"
88 gdb_test "print D::x" "= 40"
89 gdb_test "print x" "= 40"
90 gdb_test "print D::C::c" "= 30"
91 gdb_test "print C::c" "= 30"
92 gdb_test "print c" "= 30"
93 gdb_test "print D::A<int>::i" "= 1"
94}
95
96# Test some invalid expressions
97with_test_prefix "at D::f (invalid expressions)" {
98 gdb_test "print D::B<int>::c" "There is no field named c"
99 gdb_test "print D::B<int>::A<int>::c" "There is no field named c"
f7e3ecae 100
2820f08f
BL
101 if {$gcc_used} {
102 setup_xfail *-*-* gcc/60833
103 }
104 gdb_test "print D::Bint::c" "There is no field named c"
105 if {$gcc_used} {
106 setup_xfail *-*-* gcc/60833
107 }
108 gdb_test "print D::Bint::A<int>::c" "There is no field named c"
109
f7e3ecae
KS
110 gdb_test "print D::C::A<int>::c" "There is no field named c"
111 gdb_test "print B<int>::c" "There is no field named c"
112 gdb_test "print B<int>::A<int>::c" "There is no field named c"
113 gdb_test "print Bint::c" "There is no field named c"
114 gdb_test "print Bint::A<int>::c" "There is no field named c"
115 gdb_test "print C::A<int>::c" "There is no field named c"
116 gdb_test "print D::B<int>::x" "There is no field named x"
117 gdb_test "print D::B<int>::A<int>::x" "There is no field named x"
2820f08f
BL
118
119 if {$gcc_used} {
120 setup_xfail *-*-* gcc/60833
121 }
122 gdb_test "print D::Bint::x" "There is no field named x"
123 if {$gcc_used} {
124 setup_xfail *-*-* gcc/60833
125 }
126 gdb_test "print D::Bint::A<int>::x" "There is no field named x"
127
f7e3ecae
KS
128 gdb_test "print B<int>::x" "There is no field named x"
129 gdb_test "print B<int>::A<int>::x" "There is no field named x"
130 gdb_test "print Bint::x" "There is no field named x"
131 gdb_test "print Bint::A<int>::x" "There is no field named x"
132 gdb_test "print D::C::x" "There is no field named x"
133 gdb_test "print C::x" "There is no field named x"
134 gdb_test "print D::C::A<int>::x" "There is no field named x"
135 gdb_test "print C::A<int>::x" "There is no field named x"
136}
137
138# Test some ambiguous names
139with_test_prefix "at D::f (ambiguous names)" {
140 gdb_test "print B<int>::common" " = 200"
141 gdb_test "print Bint::common" " = 200"
142 gdb_test "print C::common" " = 300"
143 gdb_test "print am.i" " = 1000"
144 gdb_test "print am.A<int>::i" \
145 "base class 'A<int>' is ambiguous in type 'Ambig'"
146 gdb_test "print am.BB::A<int>::i" \
147 "base class 'A<int>' is ambiguous in type 'Ambig'"
148 gdb_test "print am.CC::A<int>::i" \
149 "base class 'A<int>' is ambiguous in type 'Ambig'"
150}