Fix PR c++/21323: GDB thinks char16_t and char32_t are signed in C++
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.cp / wide_char_types.exp
1 # This testcase is part of GDB, the GNU debugger.
2
3 # Copyright 2017 Free Software Foundation, Inc.
4
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 # Test GDB's awareness of the char16_t, char32_t (C++11+) built-in
19 # types. We also run most tests here in C mode, and check whether the
20 # built-ins are disabled (gdb uses the typedefs in the debug info
21 # instead.)
22
23 standard_testfile
24
25 # Test char16_t/char32_t in language LANG, against symbols in
26 # a program. Lang can be "c", "c++03" or "c++11". In C++11,
27 # char16_t/char32_t are built-in types, and the debug information
28 # reflects that (see
29 # http://wiki.dwarfstd.org/index.php?title=C%2B%2B0x:_New_string_literals).
30
31 proc wide_char_types_program {lang} {
32 global srcfile testfile
33
34 set options {debug}
35 if {$lang == "c++03"} {
36 lappend options c++ additional_flags=-std=c++03
37 set out $testfile-cxx03
38 } elseif {$lang == "c++11"} {
39 lappend options c++ additional_flags=-std=c++11
40 set out $testfile-cxx11
41 } else {
42 set out $testfile-c
43 }
44
45 if { [prepare_for_testing "failed to prepare" \
46 ${out} [list $srcfile] $options] } {
47 return -1
48 }
49
50 if ![runto_main] then {
51 fail "can't run to main"
52 return 0
53 }
54 do_test_wide_char $lang "u16" "u32"
55 }
56
57 # Test char16_t/char32_t in language LANG. Use CHAR16_EXP and
58 # CHAR32_EXP as expression for each of the corresponding types.
59 # (E.g., CHAR16_EXP will be u16 when testing against the program, and
60 # "(char16_t)-1" when testing the built-in types without a program
61 # loaded.)
62
63 proc do_test_wide_char {lang char16_exp char32_exp} {
64 global gdb_prompt
65
66 # Check that the fixed-width wide types are distinct built-in
67 # types in C++11+. In other modes, they're instead typedefs,
68 # found in the debug info.
69 if {$lang == "c++11"} {
70 gdb_test "ptype $char16_exp" "type = char16_t" \
71 "char16_t is distinct"
72 gdb_test "ptype $char32_exp" "type = char32_t" \
73 "char32_t is distinct"
74 } else {
75 gdb_test "ptype $char16_exp" "type = unsigned (long|int|short)" \
76 "char16_t is typedef"
77 gdb_test "ptype $char32_exp" "type = unsigned (long|int|short)" \
78 "char32_t is typedef"
79 }
80
81 # Check that the fixed-width wide char types are unsigned.
82 gdb_test "p $char16_exp" " = 65535 u'\\\\xffff'" \
83 "char16_t is unsigned"
84 gdb_test "p $char32_exp" " = 4294967295 U'\\\\xffffffff'" \
85 "char32_t is unsigned"
86
87 # Check sizeof. These are fixed-width.
88 gdb_test "p sizeof($char16_exp)" "= 2" \
89 "sizeof($char16_exp) == 2"
90 gdb_test "p sizeof($char32_exp)" "= 4" \
91 "sizeof(char16_t) == 4"
92
93 # Test printing wide literal strings. Note that when testing with
94 # no program started, this relies on GDB's awareness of the
95 # built-in wide char types.
96 gdb_test {p U"hello"} {= U"hello"}
97 gdb_test {p u"hello"} {= u"hello"}
98 }
99
100 # Make sure that the char16_t/char32_t types are recognized as
101 # distinct built-in types in C++ mode, even with no program loaded.
102 # Check that in C mode, the types are not recognized.
103
104 proc wide_char_types_no_program {} {
105 global srcfile testfile
106
107 gdb_exit
108 gdb_start
109
110 # These types are not built-in in C.
111 with_test_prefix "c" {
112 gdb_test "set language c"
113
114 gdb_test "p (char16_t) -1" "No symbol table is loaded.*" \
115 "char16_t is not built-in"
116 gdb_test "p (char32_t) -1" "No symbol table is loaded.*" \
117 "char32_t is not built-in"
118
119 gdb_test {p U"hello"} "No type named char32_t\\\."
120 gdb_test {p u"hello"} "No type named char16_t\\\."
121 }
122
123 # Note GDB does not distinguish C++ dialects, so the fixed-width
124 # types are always available in C++ mode, even if they were not
125 # built-in types before C++11.
126 with_test_prefix "c++" {
127 gdb_test "set language c++"
128
129 do_test_wide_char "c++11" "(char16_t) -1" "(char32_t) -1"
130 }
131 }
132
133 # Check wide char types with no program loaded.
134 with_test_prefix "no program" {
135 wide_char_types_no_program
136 }
137
138 # Check types when a program is loaded.
139 with_test_prefix "with program" {
140 foreach_with_prefix lang {"c" "c++03" "c++11"} {
141 wide_char_types_program $lang
142 }
143 }
This page took 0.051009 seconds and 4 git commands to generate.