aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.cp/smartp.exp
blob: 4e58cc181c22f3268e496198985647eb81d6e099 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# Copyright 2008-2016 Free Software Foundation, Inc.

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

standard_testfile .cc

if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile} {debug c++}] } {
     return -1
}

############################################

if ![runto_main] then {
    perror "couldn't run to breakpoint main"
    continue
}

gdb_breakpoint [gdb_get_line_number "end of main"]
gdb_continue_to_breakpoint "end of main"

# Test that overloaded arrow operator works
gdb_test "p mp->foo()"            "= 11"

# Test that regular arrow operator still works
gdb_test "p mtp->foo()"            "= 11"

# Test that normal '.' operator still works.
gdb_test "p mt1.foo()"             "= 11"

# test that gdb extension '.' for pointers still works.
gdb_test "p mt4p.a"                "= 11"

# test that gdb extension '->' for structs still works.
gdb_test "p mt4->a"                "= 11"

# Test that templated smart pointers work
gdb_test "p sp1->foo()"            "= 11"
gdb_test "p sp2->foo()"            "= 22"

# Test that overload resolution works properly
# with smart pointers
gdb_test "p sp3->foo(1)"           "= 33"
gdb_test "p sp3->foo('a')"         "= 44"

# Test smart pointers work for member references
gdb_test "p sp4->a"         "= 11"
gdb_test "p sp4->b"         "= 12"

# Test regular arrow operator still works for
# member references
gdb_test "p mt4p->a"         "= 11"
gdb_test "p mt4p->b"         "= 12"

# Test that incorrect use of the arrow operator
# is still handled correctly.
gdb_test "p mt4->fake"       "There is no member named fake."
gdb_test "p mt4->fake()"     "Couldn't find method Type4::fake"

# Test that overloading of -> works recursively
gdb_test "p b->foo()"         "= 66"
gdb_test "p c->foo()"         "= 66"
gdb_test "p c->inta"          "= 77"

gdb_test "p c2->inta"          "= 77"