Update copyright year range in header of all files managed by GDB
[binutils-gdb.git] / gdb / testsuite / gdb.base / ptype-offsets.cc
blobba191e0c27c424bbbbc4f38b7dab27587ac3e444
1 /* This testcase is part of GDB, the GNU debugger.
3 Copyright 2017-2023 Free Software Foundation, Inc.
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.
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.
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/>. */
18 #include <stdint.h>
20 /* A struct with many types of fields, in order to test 'ptype
21 /o'. */
23 struct abc
25 /* Virtual destructor. */
26 virtual ~abc ()
29 /* 8-byte address. Because of the virtual destructor above, this
30 field's offset will be 8. */
31 void *field1;
33 /* No hole here. */
35 /* 4-byte int bitfield of 1-bit. */
36 unsigned int field2 : 1;
38 /* 31-bit hole here. */
40 /* 4-byte int. */
41 signed int field3;
43 /* No hole here. */
45 /* 1-byte char. */
46 signed char field4;
48 /* 7-byte hole here. */
50 /* 8-byte int. */
51 uint64_t field5;
53 /* We just print the offset and size of a union, ignoring its
54 fields. */
55 union
57 /* 8-byte address. */
58 void *field6;
60 /* 4-byte int. */
61 signed int field7;
62 } field8;
64 /* Empty constructor. */
65 abc ()
68 /* Typedef defined in-struct. */
69 typedef short my_int_type;
71 my_int_type field9;
74 /* This struct will be nested inside 'struct xyz'. */
76 struct tuv
78 signed int a1;
80 signed char *a2;
82 signed int a3;
85 /* This struct will be nested inside 'struct pqr'. */
87 struct xyz
89 signed int f1;
91 signed char f2;
93 void *f3;
95 struct tuv f4;
98 /* A struct with a nested struct. */
100 struct pqr
102 signed int ff1;
104 struct xyz ff2;
106 signed char ff3;
109 /* A union with two nested structs. */
111 union qwe
113 struct tuv fff1;
115 struct xyz fff2;
118 /* A struct with an union. */
120 struct poi
122 signed int f1;
124 union qwe f2;
126 uint16_t f3;
128 struct pqr f4;
131 /* A struct with bitfields. */
133 struct tyu
135 signed int a1 : 1;
137 signed int a2 : 3;
139 signed int a3 : 23;
141 signed char a4 : 2;
143 int64_t a5;
145 signed int a6 : 5;
147 int64_t a7 : 3;
150 /* A struct with structs and unions. */
152 struct asd
154 struct jkl
156 signed char *f1;
157 union
159 void *ff1;
160 } f2;
161 union
163 signed char *ff2;
164 } f3;
165 int f4 : 5;
166 unsigned int f5 : 1;
167 short f6;
168 } f7;
169 unsigned long f8;
170 signed char *f9;
171 int f10 : 4;
172 unsigned int f11 : 1;
173 unsigned int f12 : 1;
174 unsigned int f13 : 1;
175 unsigned int f14 : 1;
176 void *f15;
177 void *f16;
180 /* See PR c++/23373. */
182 struct static_member
184 static static_member Empty;
185 int abc;
188 /* Work around PR gcc/101452. */
189 static_member static_member::Empty;
191 struct empty_member
193 struct { } empty;
194 int an_int;
198 main (int argc, char *argv[])
200 struct abc foo;
201 struct pqr bar;
202 union qwe c;
203 struct poi d;
204 struct tyu e;
205 struct asd f;
206 uint8_t i;
207 static_member stmember;
208 empty_member emember;
210 return 0;