1 # Copyright 2014, 2015 Free Software Foundation, Inc.
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.
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.
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/>.
16 # This file is part of the gdb testsuite
18 # Test expressions in which variable names shadow tag names.
20 if {[skip_cplus_tests]} { continue }
22 standard_testfile var-tag.cc var-tag-2.cc var-tag-3.cc var-tag-4.cc
24 if {[prepare_for_testing $testfile.exp $testfile \
25 [list $srcfile $srcfile2 $srcfile3 $srcfile4] {debug c++}]} {
29 proc do_global_tests {lang} {
30 set invalid_print "Attempt to use a type name as an expression"
33 set opt_underlying "(: unsigned int )?"
36 set ptypefmt "type = (class|enum|union|struct) %s $opt_underlying{.*}"
38 with_test_prefix $lang {
39 gdb_test_no_output "set language $lang"
40 gdb_test "ptype C" "type = class C {.*}"
41 gdb_test "print E" "= a"
42 gdb_test "ptype E" "type = enum E $opt_underlying{.*}"
43 gdb_test "print S" "= {<No data fields>}"
44 gdb_test "ptype S" "type = struct S {.*}"
45 gdb_test "print U" "= {.*}"
46 gdb_test "ptype U" "type = union U {.*}"
47 gdb_test "print cc" "= {.*}"
48 gdb_test "ptype cc" "type = class CC {.*}"
49 gdb_test "print CC" [format $invalid_print "CC"]
50 gdb_test "ptype CC" [format $ptypefmt "CC"]
51 gdb_test "print ss" "= {<No data fields>}"
52 gdb_test "ptype ss" "type = struct SS {.*}"
53 gdb_test "print SS" [format $invalid_print "SS"]
54 gdb_test "ptype SS" [format $ptypefmt "SS"]
55 gdb_test "print ee" "= .*"
56 gdb_test "ptype ee" "type = enum EE $opt_underlying{.*}"
57 gdb_test "print EE" [format $invalid_print "EE"]
58 gdb_test "ptype EE" [format $ptypefmt "EE"]
59 gdb_test "print uu" "= {.*}"
60 gdb_test "ptype uu" "type = union UU {.*}"
61 gdb_test "print UU" [format $invalid_print "UU"]
62 gdb_test "ptype UU" [format $ptypefmt "UU"]
64 # These tests exercise lookup of symbols using the "quick fns" API.
65 # Each of them is in a separate CU as once its CU is expanded,
66 # we're no longer using the quick fns API.
67 gdb_test "print E2" "= a2"
68 gdb_test "ptype E2" "type = enum E2 {.*}"
69 gdb_test "print S2" "= {<No data fields>}"
70 gdb_test "ptype S2" "type = struct S2 {.*}"
71 gdb_test "print U2" "= {.*}"
72 gdb_test "ptype U2" "type = union U2 {.*}"
76 # First test expressions when there is no context.
77 with_test_prefix "before start" {
82 # Run to main and test again.
84 perror "couldn't run to main"
88 with_test_prefix "in main" {
93 # Run to C::f and test again.
95 gdb_continue_to_breakpoint "continue to C::f"
96 with_test_prefix "in C::f" {
101 # Another hard-to-guess-the-users-intent bug...
102 # It would be really nice if we could query the user!
103 with_test_prefix "global collision" {
104 gdb_test_no_output "set language c++"
105 setup_kfail "c++/16463" "*-*-*"
106 gdb_test "print global" "= 3"
108 # ... with a simple workaround:
109 gdb_test "print ::global" "= 3"