Add translations for various sub-directories
[binutils-gdb.git] / gdb / testsuite / gdb.compile / compile-cplus.c
blob26979c1097cf32bfd2c5887cf42b4db4fbf48ee3
1 /* This testcase is part of GDB, the GNU debugger.
3 Copyright 2014-2024 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 <stdbool.h>
19 #include <iostream>
21 #define SOME_MACRO 23
22 #define ARG_MACRO(X, Y) ((X) + (Y) - 1)
25 enum enum_type {
26 ONE = 1,
27 TWO = 2
30 typedef int v4 __attribute__ ((vector_size (16)));
32 union union_type;
34 struct struct_type {
35 char charfield;
36 unsigned char ucharfield;
37 short shortfield;
38 unsigned short ushortfield;
39 int intfield;
40 unsigned int uintfield;
41 unsigned int bitfield : 3;
42 long longfield;
43 unsigned long ulongfield;
44 enum enum_type enumfield;
45 float floatfield;
46 double doublefield;
47 const union union_type *ptrfield;
48 struct struct_type *selffield;
49 int arrayfield[5];
50 _Complex double complexfield;
51 _Bool boolfield;
52 v4 vectorfield;
55 typedef int inttypedef;
57 union union_type {
58 int intfield;
59 inttypedef typedeffield;
62 /* volatile provides some coverage of the conversion code. */
63 volatile struct struct_type struct_object;
65 union union_type union_object;
68 enum ulonger_enum_type {
69 REALLY_MINUS_1 = -1UL,
72 enum ulonger_enum_type ulonger;
74 enum longer_enum_type {
75 MINUS_1 = -1,
76 FORCE_TO_LONG = 1L << ((8 * sizeof (long)) - 2)
79 enum longer_enum_type longer;
81 int globalvar = 10;
83 static void
84 func_static (int addend)
86 globalvar += addend;
89 void
90 func_global (int subtrahend)
92 globalvar -= subtrahend;
95 void
96 no_args_or_locals ()
98 /* no_args_or_locals breakpoint */
101 int *intptr;
102 int globalshadow = 10;
103 static int staticshadow = 20;
104 int externed = 7;
106 class Base
108 virtual int pure_virt () = 0;
109 public:
110 int return_value () {return a;}
111 private:
112 int a = 1;
113 int b = 2;
116 class Base2
118 virtual int non_pure () {return 84;}
119 public:
120 int return_value () {return b;}
121 private:
122 int a = 3;
123 int b = 4;
126 class Base3
128 public:
129 int return_value () {return b;}
130 private:
131 int b = 5;
135 class Multiple : public Base, public Base2
137 int pure_virt ()
139 int a = Base::return_value ();
140 return a + 42;
143 //struct foo { foo(); virtual ~foo(); }; struct bar : virtual foo { bar(); ~bar(); }; struct baz : bar {}; bar::bar() {} bar::~bar() {} bar t; baz u;
144 struct VirtualOnly
146 VirtualOnly();
147 virtual ~VirtualOnly()=0;
150 VirtualOnly::VirtualOnly ()
154 VirtualOnly::~VirtualOnly ()
158 struct VirtualBase : virtual VirtualOnly
160 int z = 22;
161 VirtualBase ();
162 ~VirtualBase ();
165 struct VirtualBase2 : VirtualBase {};
167 VirtualBase::VirtualBase ()
169 z = 24;
172 VirtualBase::~VirtualBase ()
174 z = 22;
177 class Foo
179 int var;
180 static const int public_static_var = 12;
182 private:
183 int private_var = 0;
184 int private_method ();
186 public:
187 int public_var = 0;
188 int public_method ();
189 void set_private_var (int);
192 void Foo::set_private_var (int i)
194 private_var = i;
197 int Foo::private_method ()
199 return private_var;
202 int Foo::public_method ()
204 return public_var;
208 main ()
210 int localvar = 50;
211 int shadowed = 51;
212 int bound = 3;
213 int unresolved = 10;
214 int globalshadow = 100;
215 int staticshadow = 200;
216 int externed = 9;
217 int f = 0;
218 int var = 0;
219 Foo foovar;
220 Multiple *multivar = new Multiple;
221 VirtualBase vbase;
222 VirtualBase2 vbase2;
223 static int static_local = 77000;
225 foovar.public_var = 42;
226 foovar.set_private_var (42);
227 multivar->Base2::return_value();
229 int another_local = 7;
230 int shadowed = 52;
231 extern int unresolved;
232 extern int externed;
234 int vla[bound];
236 func_static (0); /* break-here */
237 no_args_or_locals ();
240 return 0;