Commit | Line | Data |
---|---|---|
b50c8614 KS |
1 | # Copyright 2014 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 | # This file is part of the gdb testsuite | |
17 | ||
18 | # Test expressions in which variable names shadow tag names. | |
19 | ||
20 | if {[skip_cplus_tests]} { continue } | |
21 | ||
22 | standard_testfile .cc | |
23 | ||
24 | if {[prepare_for_testing $testfile.exp $testfile $srcfile {debug c++}]} { | |
25 | return -1 | |
26 | } | |
27 | ||
28 | proc do_global_tests {lang} { | |
36d46afb MW |
29 | if {$lang == "c++"} { |
30 | set opt_underlying "(: unsigned int )?" | |
31 | } else { | |
32 | set opt_underlying "" | |
33 | } | |
34 | ||
b50c8614 KS |
35 | if {$lang == "c"} { |
36 | set invalid_print "No symbol \"%s\" in current context." | |
37 | set ptypefmt $invalid_print | |
38 | } else { | |
39 | set invalid_print "Attempt to use a type name as an expression" | |
36d46afb | 40 | set ptypefmt "type = (class|enum|union|struct) %s $opt_underlying{.*}" |
b50c8614 KS |
41 | } |
42 | ||
43 | with_test_prefix $lang { | |
44 | gdb_test_no_output "set language $lang" | |
45 | gdb_test "ptype C" "type = class C {.*}" | |
46 | gdb_test "print E" "= a" | |
36d46afb | 47 | gdb_test "ptype E" "type = enum E $opt_underlying{.*}" |
b50c8614 KS |
48 | gdb_test "print S" "= {<No data fields>}" |
49 | gdb_test "ptype S" "type = struct S {.*}" | |
50 | gdb_test "print U" "= {.*}" | |
51 | gdb_test "ptype U" "type = union U {.*}" | |
52 | gdb_test "print cc" "= {.*}" | |
53 | gdb_test "ptype cc" "type = class CC {.*}" | |
54 | gdb_test "print CC" [format $invalid_print "CC"] | |
55 | gdb_test "ptype CC" [format $ptypefmt "CC"] | |
56 | gdb_test "print ss" "= {<No data fields>}" | |
57 | gdb_test "ptype ss" "type = struct SS {.*}" | |
58 | gdb_test "print SS" [format $invalid_print "SS"] | |
59 | gdb_test "ptype SS" [format $ptypefmt "SS"] | |
60 | gdb_test "print ee" "= .*" | |
36d46afb | 61 | gdb_test "ptype ee" "type = enum EE $opt_underlying{.*}" |
b50c8614 KS |
62 | gdb_test "print EE" [format $invalid_print "EE"] |
63 | gdb_test "ptype EE" [format $ptypefmt "EE"] | |
64 | gdb_test "print uu" "= {.*}" | |
65 | gdb_test "ptype uu" "type = union UU {.*}" | |
66 | gdb_test "print UU" [format $invalid_print "UU"] | |
67 | gdb_test "ptype UU" [format $ptypefmt "UU"] | |
68 | } | |
69 | } | |
70 | ||
71 | # First test expressions when there is no context. | |
72 | with_test_prefix "before start" { | |
73 | do_global_tests c++ | |
74 | do_global_tests c | |
75 | } | |
76 | ||
77 | # Run to main and test again. | |
78 | if {![runto_main]} { | |
79 | perror "couldn't run to main" | |
80 | continue | |
81 | } | |
82 | ||
83 | with_test_prefix "in main" { | |
84 | do_global_tests c++ | |
85 | do_global_tests c | |
86 | } | |
87 | ||
88 | # Finally run to C::f and test again | |
89 | gdb_breakpoint "C::f" | |
90 | gdb_continue_to_breakpoint "continue to C::f" | |
91 | with_test_prefix "in C::f" { | |
92 | do_global_tests c++ | |
93 | do_global_tests c | |
94 | } | |
95 | ||
96 | # Another hard-to-guess-the-users-intent bug... | |
97 | # It would be really nice if we could query the user! | |
98 | with_test_prefix "global collision" { | |
99 | gdb_test_no_output "set language c++" | |
100 | setup_kfail "c++/16463" "*-*-*" | |
101 | gdb_test "print global" "= 3" | |
102 | ||
103 | # ... with a simple workaround: | |
104 | gdb_test "print ::global" "= 3" | |
105 | } |