]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.cp/templates.exp
Automatic Copyright Year update after running gdb/copyright.py
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.cp / templates.exp
CommitLineData
4a94e368 1# Copyright 1992-2022 Free Software Foundation, Inc.
c906108c
SS
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
e22f8b7c 5# the Free Software Foundation; either version 3 of the License, or
c906108c 6# (at your option) any later version.
e22f8b7c 7#
c906108c
SS
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.
e22f8b7c 12#
c906108c 13# You should have received a copy of the GNU General Public License
e22f8b7c 14# along with this program. If not, see <http://www.gnu.org/licenses/>.
c906108c 15
c906108c
SS
16# This file was written by Fred Fish. (fnf@cygnus.com)
17
18set ws "\[\r\n\t \]+"
19
d4f3574e
SS
20if { [skip_cplus_tests] } { continue }
21
f5f3a911 22standard_testfile .cc
c906108c
SS
23
24# Create and source the file that provides information about the compiler
25# used to compile the test case.
4c93b1db 26if [get_compiler_info "c++"] {
c906108c
SS
27 return -1
28}
c906108c 29
8f5d31b8
TV
30set flags [list debug c++]
31if { [test_compiler_info gcc-*] && [gcc_major_version] >= 10 } {
32 # Work around PR gcc/101452.
33 lappend flags additional_flags=-DGCC_BUG
34}
35
36if {[prepare_for_testing "failed to prepare" $testfile $srcfile $flags]} {
f5f3a911 37 return -1
c906108c
SS
38}
39
c906108c
SS
40#
41# Test printing of the types of templates.
42#
43
44proc test_ptype_of_templates {} {
45 global gdb_prompt
46 global ws
47
bd69fc68 48 gdb_test_multiple "ptype/r T5<int>" "ptype T5<int>" {
1bc05c3a 49 -re "type = class T5<int> \{${ws}public:${ws}static int X;${ws}int x;${ws}int val;${ws}T5<int> & operator=\\(T5<int> const ?&\\);${ws}T5\\(int\\);${ws}T5\\((T5<int> const|const T5<int>) ?&\\);${ws}~T5\\((void|)\\);${ws}static void \\* operator new\\(unsigned( int| long)?\\);${ws}static void operator delete\\(void ?\\*\\);${ws}int value\\((void|)\\);${ws}\}\r\n$gdb_prompt $" {
3b7962f9 50 xfail "ptype T5<int> -- new without size_t"
c906108c 51 }
3b0cb202 52 -re "type = class T5<int> \{${ws}public:${ws}static int X;${ws}int x;${ws}int val;${ws}T5\\(int\\);${ws}T5\\((T5<int> const|const T5<int>) ?&\\);${ws}~T5\\((void|)\\);${ws}static void \\* operator new\\(unsigned( int| long)?\\);${ws}static void operator delete\\(void ?\\*\\);${ws}int value\\((void|)\\);${ws}T5<int> & operator=\\(T5<int> const ?&\\);${ws}\}\r\n$gdb_prompt $" {
3b7962f9 53 xfail "ptype T5<int> -- new without size_t"
3b0cb202 54 }
5f4d1085 55 -re "type = class T5<int> \\{${ws}public:${ws}static int X;${ws}int x;${ws}int val;${ws}${ws}T5 \\(int\\);${ws}T5 \\(const class T5<int> &\\);${ws}void ~T5 \\(()\\);${ws}static void \\* new \\(unsigned int\\);${ws}static void delete \\(void ?\\*\\);${ws}int value \\((void|)\\);${ws}\\}${ws}$gdb_prompt $" {
3b7962f9 56 xfail "ptype T5<int> -- new with unsigned int"
f8d3bf8f 57 }
5f4d1085 58 -re "type = class T5<int> \\{.*public:.*static int X;.*int x;.*int val;.*T5 \\(int\\);.*T5 \\(const class T5<int> &\\);.*void ~T5 \\(\\);.*static void \\* new \\(unsigned long\\);.*static void delete \\(void ?\\*\\);.*int value \\((void|)\\);.*\\}\r\n$gdb_prompt $" {
3b7962f9 59 xfail "ptype T5<int> -- new with unsigned long"
f8d3bf8f 60 }
1bc05c3a 61 -re "type = class T5<int> \{${ws}public:${ws}static int X;${ws}int x;${ws}int val;((${ws}T5<int> & operator=\\(T5<int> const ?&\\);)|(${ws}T5\\(int\\);)|(${ws}T5\\((T5<int> const|const T5<int>) ?&\\);)|(${ws}~T5\\((void|)\\);)|(${ws}static void \\* operator new\\(unsigned( int| long)?\\);)|(${ws}static void operator delete\\(void ?\\*\\);)|(${ws}int value\\((void|)\\);))*${ws}\}\r\n$gdb_prompt $" {
3b7962f9 62 xfail "ptype T5<int> (obsolescent gcc or gdb)"
c906108c 63 }
5f4d1085 64 -re "type = class T5<int> \{${ws}public:${ws}static int X;${ws}int x;${ws}int val;${ws}void T5\\(int\\);${ws}void T5\\((T5<int> const|const T5<int>) ?&\\);${ws}~T5\\(\\);${ws}static void \\* operator new\\((size_t|unsigned( int| long|))\\);${ws}static void operator delete\\(void ?\\*\\);${ws}int value\\((void|)\\);${ws}\}\r\n$gdb_prompt $" {
5330f2db
DC
65 # This also triggers gdb/1113...
66 kfail "gdb/1111" "ptype T5<int>"
3b7962f9 67 # Add here a PASS case when PR gdb/1111 gets fixed.
7d27a96d
TT
68 # These are really:
69 # http://sourceware.org/bugzilla/show_bug.cgi?id=8216
70 # http://sourceware.org/bugzilla/show_bug.cgi?id=8218
71 }
72 -re "type = class T5<int> \{${ws}public:${ws}static int X;${ws}int x;${ws}int val;${ws}T5\\(int\\);${ws}T5\\((T5<int> const|const T5<int>) ?&\\);${ws}~T5\\(int\\);${ws}static void \\* operator new\\((size_t|unsigned( int| long|))\\);${ws}static void operator delete\\(void ?\\*\\);${ws}int value\\((void|)\\);${ws}\}\r\n$gdb_prompt $" {
73 # http://sourceware.org/bugzilla/show_bug.cgi?id=8218
74 # The destructor has an argument type.
75 kfail "gdb/8218" "ptype T5<int>"
5330f2db 76 }
5f4d1085
KS
77 -re "type = class T5<int> \{${ws}public:${ws}static int X;${ws}int x;${ws}int val;${ws}T5\\(int\\);${ws}T5\\((T5<int> const|const T5<int>) ?&\\);${ws}~T5\\(\\);${ws}static void \\* operator new\\((size_t|unsigned( int| long|))\\);${ws}static void operator delete\\(void ?\\*\\);${ws}int value\\((void|)\\);${ws}\}\r\n$gdb_prompt $" {
78 pass "ptype T5<int>"
79 }
c906108c
SS
80 }
81
bd69fc68 82 gdb_test_multiple "ptype/r t5i" "ptype t5i" {
f8d3bf8f 83 -re "type = class T5<int> \\{${ws}public:${ws}static int X;${ws}int x;${ws}int val;\r\n${ws}T5\\(int\\);${ws}T5\\(T5<int> const ?&\\);${ws}~T5\\((void|)\\);${ws}static void \\* operator new\\(unsigned( int| long)?\\);${ws}static void operator delete\\(void ?\\*\\);${ws}int value\\((void|)\\);${ws}\\}\r\n$gdb_prompt $" {
3b7962f9 84 xfail "ptype T5<int> -- with several fixes from 4.17 -- without size_t"
f8d3bf8f 85 }
5f4d1085 86 -re "type = class T5<int> \\{${ws}public:${ws}static int X;${ws}int x;${ws}int val;\r\n${ws}T5 \\(int\\);${ws}T5 \\(const class T5<int> &\\);${ws}void ~T5 \\(\\);${ws}static void \\* new \\(unsigned int\\);${ws}static void delete \\(void ?\\*\\);${ws}int value \\((void|)\\);${ws}\\}\r\n$gdb_prompt $" {
3b7962f9 87 xfail "ptype t5i<int> -- new with unsigned int -- without size_t"
f8d3bf8f 88 }
5f4d1085 89 -re "type = class T5<int> \\{${ws}public:${ws}static int X;${ws}int x;${ws}int val;\r\n${ws}T5 \\(int\\);${ws}T5 \\(const class T5<int> &\\);${ws}void ~T5 \\(\\);${ws}static void \\* new \\(unsigned long\\);${ws}static void delete \\(void ?\\*\\);${ws}int value \\((void|)\\);${ws}\\}\r\n$gdb_prompt $" {
3b7962f9 90 xfail "ptype t5i<int> -- new with unsigned long -- without size_t"
f8d3bf8f 91 }
5f4d1085 92 -re "type = class T5<int> \{.*public:.*static int X;.*int x;.*int val;.*.*T5 \\(int\\);.*.*void ~T5 \\(\\).*.*.*int value \\((void|)\\);.*\}.*$gdb_prompt $" {
3b7962f9 93 xfail "ptype t5i -- without size_t"
a0b3c4fd 94 }
1bc05c3a 95 -re "type = class T5<int> \{${ws}public:${ws}static int X;${ws}int x;${ws}int val;${ws}T5<int> & operator=\\(T5<int> const ?&\\);${ws}T5\\(int\\);${ws}T5\\((T5<int> const|const T5<int>) ?&\\);${ws}~T5\\((void|)\\);${ws}static void \\* operator new\\(unsigned( int| long)?\\);${ws}static void operator delete\\(void ?\\*\\);${ws}int value\\((void|)\\);${ws}\}\r\n$gdb_prompt $" {
3b7962f9 96 xfail "ptype t5i -- without size_t"
c906108c 97 }
3b0cb202 98 -re "type = class T5<int> \{${ws}public:${ws}static int X;${ws}int x;${ws}int val;${ws}T5\\(int\\);${ws}T5\\((T5<int> const|const T5<int>) ?&\\);${ws}~T5\\((void|)\\);${ws}static void \\* operator new\\(unsigned( int| long)?\\);${ws}static void operator delete\\(void ?\\*\\);${ws}int value\\((void|)\\);${ws}T5<int> & operator=\\(T5<int> const ?&\\);${ws}\}\r\n$gdb_prompt $" {
3b7962f9 99 xfail "ptype t5i -- without size_t"
3b0cb202 100 }
3b2a7ae5 101 -re "type = class T5<int> \{${ws}public:${ws}static int X;${ws}int x;${ws}int val;((${ws}T5<int> & operator=\\(T5<int> const ?&\\);)|(${ws}T5\\(int\\);)|(${ws}T5\\(T5<int> const ?&\\);)|(${ws}~T5\\((void|)\\);)|(${ws}static void \\* operator new\\(unsigned( int| long)?\\);)|(${ws}static void operator delete\\(void ?\\*\\);)|(${ws}int value\\((void|)\\);))*${ws}\}\r\n$gdb_prompt $" {
3b7962f9 102 xfail "ptype t5i (obsolescent gcc or gdb) -- without size_t"
c906108c 103 }
5f4d1085 104 -re "type = class T5<int> \{${ws}public:${ws}static int X;${ws}int x;${ws}int val;${ws}void T5\\(int\\);${ws}void T5\\((T5<int> const|const T5<int>) ?&\\);${ws}~T5\\(\\);${ws}static void \\* operator new\\((size_t|unsigned( int| long|))\\);${ws}static void operator delete\\(void ?\\*\\);${ws}int value\\((void|)\\);${ws}\}\r\n$gdb_prompt $" {
5330f2db 105 # This also triggers gdb/1113...
5f4d1085 106 kfail "gdb/1111" "ptype t5i"
3b7962f9 107 # Add here a PASS case when PR gdb/1111 gets fixed.
7d27a96d
TT
108 # These are really:
109 # http://sourceware.org/bugzilla/show_bug.cgi?id=8216
110 # http://sourceware.org/bugzilla/show_bug.cgi?id=8218
111 }
112 -re "type = class T5<int> \{${ws}public:${ws}static int X;${ws}int x;${ws}int val;${ws}T5\\(int\\);${ws}T5\\((T5<int> const|const T5<int>) ?&\\);${ws}~T5\\(int\\);${ws}static void \\* operator new\\((size_t|unsigned( int| long|))\\);${ws}static void operator delete\\(void ?\\*\\);${ws}int value\\((void|)\\);${ws}\}\r\n$gdb_prompt $" {
113 # http://sourceware.org/bugzilla/show_bug.cgi?id=8218
114 # The destructor has an argument type.
5f4d1085
KS
115 kfail "gdb/8218" "ptype t5i"
116 }
117 -re "type = class T5<int> \{${ws}public:${ws}static int X;${ws}int x;${ws}int val;${ws}T5\\(int\\);${ws}T5\\((T5<int> const|const T5<int>) ?&\\);${ws}~T5\\(\\);${ws}static void \\* operator new\\((size_t|unsigned( int| long|))\\);${ws}static void operator delete\\(void ?\\*\\);${ws}int value\\((void|)\\);${ws}\}\r\n$gdb_prompt $" {
118 pass "ptype t5i"
5330f2db 119 }
c906108c
SS
120 }
121}
122
123#
124# Test breakpoint setting on template methods.
125#
126
127proc test_template_breakpoints {} {
128 global gdb_prompt
129 global testfile
130 global srcdir
131
b598bfda 132 gdb_test_multiple "break T5<int>::T5" "constructor breakpoint" {
f8eba3c6 133 -re "0. cancel.*\[\r\n\]*.1. all.*\[\r\n\]*.2.*templates.cc:T5<int>::T5\\((T5<int> const|const T5<int>) ?&\\)\[\r\n\]*.3.*templates.cc:T5<int>::T5\\(int\\)\[\r\n\]*> $" {
c906108c 134 gdb_test "0" \
a9e2e984 135 "canceled" \
c906108c
SS
136 "constructor breakpoint"
137 }
5330f2db
DC
138 -re "0. cancel.*\[\r\n\]*.1. all.*\[\r\n\]*.2. T5 at .*\[\r\n\]*.3. T5 at .*\[\r\n\]*> $" {
139 setup_kfail "gdb/1062" "*-*-*"
140 gdb_test "0" \
141 "nonsense intended to insure that this test fails" \
142 "constructor breakpoint"
143 }
760f6330
MS
144 -re ".*\n> $" {
145 gdb_test "0" \
146 "nonsense intended to insure that this test fails" \
147 "constructor breakpoint (bad menu choices)"
148 }
c906108c
SS
149 }
150
5330f2db
DC
151 gdb_test_multiple "break T5<int>::~T5" "destructor_breakpoint" {
152 -re "Breakpoint.*at.* file .*${testfile}.cc, line.*$gdb_prompt $"
153 {
154 pass "destructor breakpoint"
155 }
156 -re "the class `T5<int>' does not have destructor defined\r\nHint: try 'T5<int>::~T5<TAB> or 'T5<int>::~T5<ESC-\\?>\r\n\\(Note leading single quote.\\)\r\n$gdb_prompt $"
157 {
158 kfail "gdb/1112" "destructor breakpoint"
159 }
160 }
c906108c
SS
161
162 gdb_test "break T5<int>::value" \
163 "Breakpoint.*at.* file .*${testfile}.cc, line.*" \
164 "value method breakpoint"
165
945a118d
JG
166 set bp_location [gdb_get_line_number \
167 "set breakpoint on a line with no real code"]
f8eba3c6
TT
168
169 gdb_test_multiple "break ${testfile}.cc:${bp_location}" \
170 "breakpoint on a line with no real code" {
171 -re "0. cancel.*\[\r\n\]*.1. all.*\[\r\n\]*.2.*templates.cc:GetMax<int>\\(int, int\\)\[\r\n\]*.3.*templates.cc:GetMax<long>\\(long, long\\)\[\r\n\]*> $" {
172 gdb_test "0" \
173 "canceled" \
174 "breakpoint on a line with no real code"
175 }
176 -re "0. cancel.*\[\r\n\]*.1. all.*\[\r\n\]*.2.*\[\r\n\]*.3.*\[\r\n\]*> $" {
177 gdb_test "0" \
178 "nonsense intended to insure that this test fails" \
179 "breakpoint on a line with no real code"
180 }
181 -re ".*\n> $" {
182 gdb_test "0" \
183 "nonsense intended to insure that this test fails" \
184 "breakpoint on a line with no real code"
185 }
186 }
187
c906108c
SS
188 delete_breakpoints
189}
190
191#
192# Test calling of template methods.
193#
194
195proc test_template_calls {} {
196 global gdb_prompt
197
198 if [target_info exists gdb,cannot_call_functions] {
bc6c7af4 199 unsupported "this target can not call functions"
c906108c
SS
200 return
201 }
202
b6304613 203 setup_xfail hppa*-*-*
f8d3bf8f
MS
204 gdb_test_multiple "print t5i.value()" "print t5i.value()" {
205 -re ".* = 2\[\r\n\]*$gdb_prompt $" {
206 pass "print t5i.value()"
207 }
c906108c
SS
208 -re "Cannot invoke functions on this machine.*$gdb_prompt $" {
209 fail "print t5i.value()"
210 }
a0b3c4fd
JM
211 -re "Cannot resolve .* to any overloaded instance.*$gdb_prompt $" {
212 setup_xfail hppa*-*-* CLLbs16899
213 xfail "print t5i.value"
214 }
c906108c
SS
215 }
216}
217
3fe8f3b3 218proc test_template_typedef {} {
ae1a303e 219 global gdb_prompt
3fe8f3b3
KS
220
221 gdb_test "print intBazOne::baz" ".*baz\\(int, int\\)>" \
222 "print method of template typedef"
223
ae1a303e
JK
224 set test "print destructor of template typedef"
225 gdb_test_multiple "print intBazOne::~Baz" $test {
226 -re "~Baz(\\(\\))?>\r\n$gdb_prompt $" {
227 pass $test
228 }
229 -re "There is no field named ~Baz\r\n$gdb_prompt $" {
230 set test2 "verify GCC PR debug/51668"
231 gdb_test_multiple "whatis intBazOne" $test2 {
232 -re "type = Baz<int, \\(char\\)'\\\\001'>\r\n$gdb_prompt $" {
233 setup_xfail gcc/51668 "*-*-*"
234 xfail $test
235 pass $test2
236 }
237 -re "\r\n$gdb_prompt $" {
238 # Some unexpected response.
239 fail $test
240 fail $test2
241 }
242 }
243 }
244 }
3fe8f3b3 245}
c906108c 246
c767944b
DJ
247proc test_template_args {} {
248
249 set empty_re "Empty *<void *\\(FunctionArg *<int>\\)>"
bd69fc68
TT
250 gdb_test "ptype/r empty" \
251 "type = (struct|class) $empty_re {.*<no data fields>.*}" \
252 "ptype empty"
c767944b 253
bd69fc68
TT
254 gdb_test "ptype/r arg" \
255 "type = (struct|class) FunctionArg<int> {.*int method\\($empty_re \\&\\);.*}" \
256 "ptype arg"
c767944b
DJ
257}
258
c906108c 259proc do_tests {} {
eae06beb
JB
260 # Change multiple-symbols to "ask" in order to get the multiple-choice
261 # menu when breaking on overloaded methods.
a8d52276 262 gdb_test_no_output "set multiple-symbols ask"
eae06beb 263
40f235b7 264 runto_main
c906108c
SS
265
266 test_ptype_of_templates
267 test_template_breakpoints
3fe8f3b3 268 test_template_typedef
c767944b 269 test_template_args
c906108c
SS
270
271 if [ runto_main] {
272 test_template_calls
273 }
274}
275
276do_tests
277
a0b3c4fd
JM
278
279# More tests for different kinds of template parameters,
280# templates with partial specializations, nested templates, etc.
707ed39a
AB
281
282gdb_breakpoint [gdb_get_line_number "Final breakpoint"]
283gdb_continue_to_breakpoint "Final breakpoint"
f8d3bf8f
MS
284
285gdb_test "print fint" \
286 "\\$\[0-9\]* = \\{x = 0, t = 0\\}"
287
775e0f04
YQ
288# Prevent symbol on address 0x0 being printed.
289gdb_test_no_output "set print symbol off"
f8d3bf8f
MS
290gdb_test "print fvpchar" \
291 "\\$\[0-9\]* = \\{x = 0, t = 0x0\\}"
a0b3c4fd
JM
292
293# Template Foo<T>
294
dd14ab43
DC
295# Neither stabs nor DWARF-2 contains type information about templates
296# (as opposed to instantiations of templates), so in those
297# circumstances we expect GDB to not find a symbol. HP has a debug
298# format that contains more info, though, so it's also correct to
299# print out template info. (This affects several subsequent tests as
300# well.)
301
302# NOTE: carlton/2003-02-26: However, because of a bug in the way GDB
303# handles nested types, we don't get this right in the DWARF-2 case.
304
bd69fc68 305gdb_test_multiple "ptype/r Foo" "ptype Foo" {
f8d3bf8f
MS
306 -re "type = template <(class |)T> (class |)Foo \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*T t;\r\n\\}\r\ntemplate instantiations:\r\n\[ \t\]*(class |)Foo<volatile char \\*>\r\n\[ \t\]*(class |)Foo<char>\r\n\[ \t\]*(class |)Foo<int>\r\n$gdb_prompt $" {
307 pass "ptype Foo"
308 }
309 -re "type = template <(class |)T> (class |)Foo \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*T t;\r\n\\}\r\n$gdb_prompt $" {
310 xfail "ptype Foo"
311 }
312 -re "type = class Foo<int> \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*int t;\r\n\r\n\[ \t\]*int foo\\(int, int\\);\r\n\\}\r\n$gdb_prompt $" {
313 # GCC 3.1, DWARF-2 output.
314 kfail "gdb/57" "ptype Foo"
315 }
316 -re "No symbol \"Foo\" in current context.\r\n$gdb_prompt $" {
317 # GCC 2.95.3, stabs+ output.
318 pass "ptype Foo"
319 }
a0b3c4fd 320}
f8d3bf8f 321
dd14ab43 322# -re "type = class Foo<int> \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*int t;\r\n\r\n\[ \t\]*int foo(int, int);\r\n\\}\r\n$gdb_prompt $"
a0b3c4fd
JM
323
324# ptype Foo<int>
325
bd69fc68 326gdb_test_multiple "ptype/r fint" "ptype fint" {
f8d3bf8f
MS
327 -re "type = (class |)Foo<int> \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*int t;\r\n\r\n\[ \t\]*.*int foo\\(int, int\\);\r\n\\}\r\n$gdb_prompt $" {
328 pass "ptype fint"
329 }
330 -re "type = (class |)Foo<int> \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*int t;\r\n\r\n\[ \t\]*int foo\\(int, int\\);.*\r\n\\}\r\n$gdb_prompt $" {
331 pass "ptype fint"
332 }
a0b3c4fd
JM
333}
334
335# ptype Foo<char>
336
bd69fc68 337gdb_test_multiple "ptype/r fchar" "ptype fchar" {
f8d3bf8f
MS
338 -re "type = (class |)Foo<char> \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*char t;\r\n\r\n\[ \t\]*.*char foo\\(int, char\\);\r\n\\}\r\n$gdb_prompt $" {
339 pass "ptype fchar"
340 }
341 -re "type = (class |)Foo<char> \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*char t;\r\n\r\n\[ \t\]*char foo\\(int, char\\);.*\r\n\\}\r\n$gdb_prompt $" {
342 pass "ptype fchar"
343 }
a0b3c4fd
JM
344}
345
346# ptype Foo<volatile char *>
347
bd69fc68 348gdb_test_multiple "ptype/r fvpchar" "ptype fvpchar" {
f8d3bf8f
MS
349 -re "type = (class |)Foo<volatile char ?\\*> \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*.*char.*\\*t;\r\n\r\n\[ \t\]*.*char \\* foo\\(int,.*char.*\\*\\);\r\n\\}\r\n$gdb_prompt $" {
350 pass "ptype fvpchar"
351 }
352 -re "type = (class |)Foo<volatile char ?\\*> \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*.*char.*\\*t;\r\n\r\n\[ \t\]*.*char \\* foo\\(int,.*char.*\\*\\);.*\r\n\\}\r\n$gdb_prompt $" {
353 pass "ptype fvpchar"
354 }
355 -re "type = (class |)Foo<char volatile ?\\*> \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*.*char.*\\*t;\r\n\r\n\[ \t\]*.*char \\* foo\\(int,.*char.*\\*\\);\r\n\\}\r\n$gdb_prompt $" {
356 kfail "gdb/1512" "ptype fvpchar"
357 }
a0b3c4fd
JM
358}
359
360# print a function from Foo<volatile char *>
361
0b71dc91
DC
362# This test is sensitive to whitespace matching, so we'll do it twice,
363# varying the spacing, because of PR gdb/33.
364
f8d3bf8f
MS
365gdb_test_multiple "print Foo<volatile char *>::foo" "print Foo<volatile char *>::foo" {
366 -re "\\$\[0-9\]* = \\{.*char \\*\\((class |)Foo<(volatile char|char volatile) ?\\*> \\*(| const), int, .*char \\*\\)\\} $hex <Foo<.*char.*\\*>::foo\\(int, .*char.*\\*\\)>\r\n$gdb_prompt $" {
367 pass "print Foo<volatile char *>::foo"
368 }
369 -re "No symbol \"Foo<volatile char \\*>\" in current context.\r\n$gdb_prompt $" {
71c25dea
TT
370 # This used to be a kfail gdb/33 and then kfail gdb/931.
371 fail "print Foo<volatile char *>::foo"
85ca1584 372 }
0b71dc91
DC
373}
374
f8d3bf8f
MS
375gdb_test_multiple "print Foo<volatile char*>::foo" "print Foo<volatile char*>::foo" {
376 -re "\\$\[0-9\]* = \\{.*char \\*\\((class |)Foo<(volatile char|char volatile) ?\\*> \\*(| const), int, .*char \\*\\)\\} $hex <Foo<.*char.*\\*>::foo\\(int, .*char.*\\*\\)>\r\n$gdb_prompt $" {
377 pass "print Foo<volatile char*>::foo"
378 }
379 -re "No symbol \"Foo<volatile char\\*>\" in current context.\r\n$gdb_prompt $" {
71c25dea
TT
380 # This used to be a kfail gdb/33 and then kfail gdb/931.
381 fail "print Foo<volatile char*>::foo"
85ca1584 382 }
a0b3c4fd
JM
383}
384
385# Template Bar<T, int>
386
e6d71bf3 387# same as Foo for g++
bd69fc68 388gdb_test_multiple "ptype/r Bar" "ptype Bar" {
f8d3bf8f
MS
389 -re "type = template <(class |)T, (class |)sz> (class |)Bar \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*T t;\r\n\\}\r\ntemplate instantiations:\r\n\[ \t\]*(class |)Bar<int,(\\(int\\)|)1>\r\n\[ \t\]*(class |)Bar<int,(\\(int\\)|)33>\r\n$gdb_prompt $" {
390 pass "ptype Bar"
391 }
392 -re "type = <(class |)T, (class |)sz> (class |)Bar \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*T t;\r\n\\}\r\n$gdb_prompt $" {
393 xfail "ptype Bar"
394 }
395 -re "ptype Bar\r\ntype = class Bar<int, ?33> {\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*int t;\r\n\r\n\[ \t\]*int bar\\(int, int\\);\r\n}\r\n$gdb_prompt $" {
396 # GCC 3.1, DWARF-2 output.
397 kfail "gdb/57" "ptype Bar"
398 }
399 -re "No symbol \"Bar\" in current context.\r\n$gdb_prompt $" {
400 # GCC 2.95.3, stabs+ output.
401 pass "ptype Bar"
402 }
a0b3c4fd
JM
403}
404
405
406# ptype Bar<int,33>
5a2a0a20 407
bd69fc68 408gdb_test_multiple "ptype/r bint" "ptype bint" {
f8d3bf8f
MS
409 -re "type = (class |)Bar<int, ?(\\(int\\)|)33> \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*int t;\r\n\r\n\[ \t\]*.*int bar\\(int, int\\);\r\n\\}\r\n$gdb_prompt $" {
410 pass "ptype bint"
411 }
412 -re "type = (class |)Bar<int,(\\(int\\)|)33> \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*int t;\r\n\r\n\[ \t\]*int bar\\(int, int\\);.*\r\n\\}\r\n$gdb_prompt $" {
413 pass "ptype bint"
414 }
a0b3c4fd
JM
415}
416
417# ptype Bar<int, (4>3)>
418
bd69fc68 419gdb_test_multiple "ptype/r bint2" "ptype bint2" {
f8d3bf8f
MS
420 -re "type = (class |)Bar<int, ?(\\(int\\)|)1> \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*int t;\r\n\r\n\[ \t\]*.*int bar\\(int, int\\);\r\n\\}\r\n$gdb_prompt $" {
421 pass "ptype bint2"
422 }
423 -re "type = (class |)Bar<int,(\\(int\\)|)1> \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*int t;\r\n\r\n\[ \t\]*int bar\\(int, int\\);.*\r\n\\}\r\n$gdb_prompt $" {
424 pass "ptype bint2"
425 }
a0b3c4fd
JM
426}
427
428# Template Baz<T, char>
429
e6d71bf3 430# Same as Foo, for g++
bd69fc68 431gdb_test_multiple "ptype/r Baz" "ptype Baz" {
f8d3bf8f
MS
432 -re "type = template <(class |)T, ?(class |)sz> (class |)Baz \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*T t;\r\n\\}\r\ntemplate instantiations:\r\n\[ \t\]*(class |)Baz<char,(\\(char\\)|)97>\r\n\[ \t\]*(class |)Baz<int,(\\(char\\)|)115>\r\n$gdb_prompt $" {
433 pass "ptype Baz"
434 }
435 -re "type = <(class |)T, ?(class |)sz> (class |)Baz \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*T t;\r\n\\}\r\n$gdb_prompt $" {
436 xfail "ptype Baz"
437 }
438 -re "type = class Baz<int, ?'s'> {\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*int t;\r\n\r\n\[ \t\]*int baz\\(int, int\\);\r\n}\r\n$gdb_prompt $" {
439 # GCC 3.1, DWARF-2 output.
440 kfail "gdb/57" "ptype Baz"
441 }
442 -re "type = class Baz<int, ?(\\(char\\))?115> {\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*int t;\r\n\r\n\[ \t\]*int baz\\(int, int\\);\r\n}\r\n$gdb_prompt $" {
443 # GCC 3.x, DWARF-2 output, running into gdb/57 and gdb/1512.
444 kfail "gdb/57" "ptype Baz"
445 }
446 -re "No symbol \"Baz\" in current context.\r\n$gdb_prompt $" {
447 # GCC 2.95.3, stabs+ output.
448 pass "ptype Baz"
449 }
a0b3c4fd
JM
450}
451
452
453# ptype Baz<int, 's'>
454
bd69fc68 455gdb_test_multiple "ptype/r bazint" "ptype bazint" {
f8d3bf8f
MS
456 -re "type = (class |)Baz<int, ?(\\(char\\)|)(115|\\'s\\')> \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*int t;\r\n\r\n\[ \t\]*.*int baz\\(int, int\\);\r\n\\}\r\n$gdb_prompt $" {
457 pass "ptype bazint"
458 }
459 -re "type = (class |)Baz<int,(\\(char\\)|)(115|\\'s\\')> \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*int t;\r\n\r\n\[ \t\]*int baz\\(int, int\\).*;\r\n\\}\r\n$gdb_prompt $" {
460 pass "ptype bazint"
461 }
a0b3c4fd
JM
462}
463
464# ptype Baz<char, 'a'>
465
bd69fc68 466gdb_test_multiple "ptype/r bazint2" "ptype bazint2" {
f8d3bf8f
MS
467 -re "type = (class |)Baz<char, ?(\\(char\\)|)(97|\\'a\\')> \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*char t;\r\n\r\n\[ \t\]*.*char baz\\(int, char\\);\r\n\\}\r\n$gdb_prompt $" {
468 pass "ptype bazint2"
469 }
470 -re "type = (class |)Baz<char,(\\(char\\)|)(97|\\'a\\')> \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*char t;\r\n\r\n\[ \t\]*char baz\\(int, char\\);.*\r\n\\}\r\n$gdb_prompt $" {
471 pass "ptype bazint2"
472 }
a0b3c4fd
JM
473}
474
475# Template Qux<T, int (*f)(int) >
e6d71bf3 476# Same as Foo for g++
bd69fc68 477gdb_test_multiple "ptype/r Qux" "ptype Qux" {
f8d3bf8f
MS
478 -re "type = template <(class |)T, ?(class |)sz> (class |)Qux \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*T t;\r\n\\}\r\ntemplate instantiations:\r\n\[ \t\]*(class |)Qux<int,&string>\r\n\[ \t\]*(class |)Qux<char,&string>\r\n$gdb_prompt $" {
479 pass "ptype Qux"
480 }
481 -re ".*type = template <(class |)T.*, ?(class |)sz> (class |)Qux \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*T t;\r\n\\}.*$gdb_prompt $" {
482 pass "ptype Qux"
483 }
484 -re "type = class Qux<char, ?&string> {\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*char t;\r\n\r\n\[ \t\]*char qux\\(int, char\\);\r\n}\r\n$gdb_prompt $" {
485 # GCC 3.1, DWARF-2 output.
486 kfail "gdb/57" "ptype Qux"
487 }
488 -re "type = class Qux<char, ?&\\(string\\)> {\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*char t;\r\n\r\n\[ \t\]*char qux\\(int, char\\);\r\n}\r\n$gdb_prompt $" {
489 # GCC 3.x, DWARF-2 output; gdb/57 + gdb/1512.
490 kfail "gdb/57" "ptype Qux"
491 }
492 -re "No symbol \"Qux\" in current context.\r\n$gdb_prompt $" {
493 # GCC 2.95.3, stabs+ output.
494 pass "ptype Qux"
495 }
a0b3c4fd
JM
496}
497
498# pt Qux<int,&string>
499
bd69fc68 500gdb_test_multiple "ptype/r quxint" "ptype quxint" {
f8d3bf8f
MS
501 -re "type = class Qux<int, ?& ?string> \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*int t;\r\n\r\n\[ \t\]*.*int qux\\(int, int\\);\r\n\\}\r\n$gdb_prompt $" {
502 pass "ptype quxint"
503 }
748aa9b6
AKS
504 -re "type = class Qux<int, string> \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*int t;\r\n\r\n\[ \t\]*.*int qux\\(int, int\\);\r\n\\}\r\n$gdb_prompt $" {
505 pass "ptype quxint"
506 }
f8d3bf8f
MS
507 -re "type = class Qux<int, ?& ?string> \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*int t;\r\n\r\n\[ \t\]*int qux\\(int, int\\);.*\r\n\\}\r\n$gdb_prompt $" {
508 pass "ptype quxint"
509 }
510 -re "type = class Qux<int, ?\\(char ?\\*\\)\\(& ?\\(?string\\)?\\)> \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*int t;\r\n\r\n\[ \t\]*int qux\\(int, int\\);.*\r\n\\}\r\n$gdb_prompt $" {
511 pass "ptype quxint"
512 }
513 -re "type = class Qux<int, ?& ?\\(string\\)> \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*int t;\r\n\r\n\[ \t\]*int qux\\(int, int\\);.*\r\n\\}\r\n$gdb_prompt $" {
514 kfail "gdb/1512" "ptype quxint"
515 }
a0b3c4fd
JM
516}
517
a0b3c4fd
JM
518
519# Template Spec<T1, T2>
520
e6d71bf3 521# Same as Foo for g++
bd69fc68 522gdb_test_multiple "ptype/r Spec" "ptype Spec" {
f8d3bf8f
MS
523 -re "type = template <(class |)T1, (class |)T2> (class |)Spec \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\\}\r\ntemplate instantiations:\r\n\[ \t\]*(class |)Spec<int,int \\*>\r\n\[ \t\]*(class |)Spec<int,char>\r\n$gdb_prompt $" {
524 pass "ptype Spec"
525 }
526 -re "type = <(class |)T1, (class |)T2> (class |)Spec \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\\}\r\n$gdb_prompt $" {
527 xfail "ptype Spec"
528 }
529 -re "type = class Spec<int, ?char> {\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\r\n\[ \t\]*int spec\\(char\\);\r\n}\r\n$gdb_prompt $" {
530 # GCC 3.1, DWARF-2 output.
531 kfail "gdb/57" "ptype Spec"
532 }
533 -re "No symbol \"Spec\" in current context.\r\n$gdb_prompt $" {
534 # GCC 2.95.3, stabs+ output.
535 pass "ptype Spec"
536 }
a0b3c4fd
JM
537}
538
539# pt Spec<char,0>
540
bd69fc68 541gdb_test_multiple "ptype/r siip" "ptype siip" {
f8d3bf8f
MS
542 -re "type = class Spec<int, ?int ?\\*> \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\r\n\[ \t\]*.*int spec\\(int ?\\*\\);\r\n\\}\r\n$gdb_prompt $" {
543 pass "ptype siip"
544 }
545 -re "type = class Spec<int,int ?\\*> \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\r\n\[ \t\]*int spec\\(int ?\\*\\);.*\r\n\\}\r\n$gdb_prompt $" {
546 pass "ptype siip"
547 }
a0b3c4fd
JM
548}
549
999a4952
CS
550# Check cv qualifiers and substitute parameters.
551
552if {[test_compiler_info {clang-*}]} {
553 setup_kfail "llvm/52262 " "*-*-*"
554}
555gdb_test "ptype cfoo" [multi_line \
556"type = (class |)Cfoo<double> \\\[with DataT = double\\\] \\{" \
557 "\[ \t\]*public:" \
558 "\[ \t\]*DataT me0;" \
559 "\[ \t\]*const DataT me1;" \
560 "\[ \t\]*const myfloat me2;" \
561 "\[ \t\]*const int me3;" \
562 "" \
563 "\[ \t\]*private:" \
564 "\[ \t\]*typedef float myfloat;" \
565"\\}" \
566] "print type of cfoo"
567
568# Check cv qualifiers and do not substitute.
569
570if {[test_compiler_info {clang-*}]} {
571 setup_kfail "llvm/52262 " "*-*-*"
572}
573gdb_test "ptype/r cfoo" [multi_line \
574"type = (class |)Cfoo<double> \\{" \
575 "\[ \t\]*public:" \
576 "\[ \t\]*double me0;" \
577 "\[ \t\]*const double me1;" \
578 "\[ \t\]*const Cfoo<double>::myfloat me2;" \
579 "\[ \t\]*const int me3;" \
580 "" \
581 "\[ \t\]*private:" \
582 "\[ \t\]*typedef float myfloat;" \
583"\\}" \
584] "print raw type of cfoo"
585
a0b3c4fd
JM
586# pt Garply<int>
587
bd69fc68 588gdb_test_multiple "ptype/r Garply<int>" "ptype Garply<int>" {
f8d3bf8f
MS
589 -re "type = class Garply<int> \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*int t;\r\n\r\n\[ \t\]*.*int garply\\(int, int\\);\r\n\\}\r\n$gdb_prompt $" {
590 pass "ptype Garply<int>"
591 }
592 -re "type = class Garply<int> \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*int t;\r\n\r\n\[ \t\]*int garply\\(int, int\\);.*\r\n\\}\r\n$gdb_prompt $" {
593 pass "ptype Garply<int>"
594 }
a0b3c4fd
JM
595}
596
597# ptype of nested template name
598
bd69fc68 599gdb_test_multiple "ptype/r Garply<Garply<char> >" "ptype Garply<Garply<char> >" {
f8d3bf8f
MS
600 -re "type = (class |)Garply<Garply<char> > \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*.*(class |)Garply<char> t;\r\n\r\n\[ \t\]*.*(class |)Garply<char> garply\\(int, (class |)Garply<char>\\);\r\n\\}\r\n$gdb_prompt $" {
601 pass "ptype Garply<Garply<char> >"
602 }
603 -re "type = (class |)Garply<Garply<char> > \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*.*(class |)Garply<char> t;\r\n\r\n\[ \t\]*(class |)Garply<char> garply\\(int, (class |)Garply<char>\\);.*\r\n\\}\r\n$gdb_prompt $" {
604 pass "ptype Garply<Garply<char> >"
605 }
a0b3c4fd
JM
606}
607
608# print out a function from a nested template name
609
f8d3bf8f 610gdb_test "print Garply<Garply<char> >::garply" \
e96ec2ba 611 "\\$\[0-9\]* = \\{(class |)Garply<char> \\((class |)Garply<Garply<char> > \\*(| const), int, (class |)Garply<char>\\)\\} $hex <Garply<Garply<char>\[ \t\]*>::garply\\(int, (class |)Garply<char>\\)>"
a0b3c4fd 612
e6d71bf3
DB
613# djb - 06-03-2000
614# Now should work fine
b598bfda
DJ
615gdb_test "break Garply<Garply<char> >::garply" \
616 "Breakpoint \[0-9\]* at $hex: file .*templates.cc, line.*"