1/* This testcase is part of GDB, the GNU debugger. 2 3 Copyright 2014-2020 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#include <stdbool.h> 19#include <iostream> 20 21#define SOME_MACRO 23 22#define ARG_MACRO(X, Y) ((X) + (Y) - 1) 23 24 25enum enum_type { 26 ONE = 1, 27 TWO = 2 28}; 29 30typedef int v4 __attribute__ ((vector_size (16))); 31 32union union_type; 33 34struct 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; 53}; 54 55typedef int inttypedef; 56 57union union_type { 58 int intfield; 59 inttypedef typedeffield; 60}; 61 62/* volatile provides some coverage of the conversion code. */ 63volatile struct struct_type struct_object; 64 65union union_type union_object; 66 67 68enum ulonger_enum_type { 69 REALLY_MINUS_1 = -1UL, 70}; 71 72enum ulonger_enum_type ulonger; 73 74enum longer_enum_type { 75 MINUS_1 = -1, 76 FORCE_TO_LONG = 1L << ((8 * sizeof (long)) - 2) 77}; 78 79enum longer_enum_type longer; 80 81int globalvar = 10; 82 83static void 84func_static (int addend) 85{ 86 globalvar += addend; 87} 88 89void 90func_global (int subtrahend) 91{ 92 globalvar -= subtrahend; 93} 94 95void 96no_args_or_locals () 97{ 98 /* no_args_or_locals breakpoint */ 99} 100 101int *intptr; 102int globalshadow = 10; 103static int staticshadow = 20; 104int externed = 7; 105 106class Base 107{ 108 virtual int pure_virt () = 0; 109 public: 110 int return_value () {return a;} 111 private: 112 int a = 1; 113 int b = 2; 114}; 115 116class Base2 117{ 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; 124}; 125 126class Base3 127{ 128 public: 129 int return_value () {return b;} 130 private: 131 int b = 5; 132}; 133 134 135class Multiple : public Base, public Base2 136{ 137 int pure_virt () 138 { 139 int a = Base::return_value (); 140 return a + 42; 141 } 142}; 143//struct foo { foo(); virtual ~foo(); }; struct bar : virtual foo { bar(); ~bar(); }; struct baz : bar {}; bar::bar() {} bar::~bar() {} bar t; baz u; 144struct VirtualOnly 145{ 146 VirtualOnly(); 147 virtual ~VirtualOnly()=0; 148}; 149 150VirtualOnly::VirtualOnly () 151{ 152} 153 154VirtualOnly::~VirtualOnly () 155{ 156} 157 158struct VirtualBase : virtual VirtualOnly 159{ 160 int z = 22; 161 VirtualBase (); 162 ~VirtualBase (); 163}; 164 165struct VirtualBase2 : VirtualBase {}; 166 167VirtualBase::VirtualBase () 168{ 169 z = 24; 170} 171 172VirtualBase::~VirtualBase () 173{ 174 z = 22; 175} 176 177class Foo 178{ 179 int var; 180 static const int public_static_var = 12; 181 182 private: 183 int private_var = 0; 184 int private_method (); 185 186 public: 187 int public_var = 0; 188 int public_method (); 189 void set_private_var (int); 190}; 191 192void Foo::set_private_var (int i) 193{ 194 private_var = i; 195} 196 197int Foo::private_method () 198{ 199 return private_var; 200} 201 202int Foo::public_method () 203{ 204 return public_var; 205} 206 207int 208main () 209{ 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; 224 225 foovar.public_var = 42; 226 foovar.set_private_var (42); 227 multivar->Base2::return_value(); 228 { 229 int another_local = 7; 230 int shadowed = 52; 231 extern int unresolved; 232 extern int externed; 233 234 int vla[bound]; 235 236 func_static (0); /* break-here */ 237 no_args_or_locals (); 238 } 239 240 return 0; 241} 242