summaryrefslogtreecommitdiffstats
path: root/kdbg/testprogs/testfile.cpp
blob: 242c5043c2f7d9937b5a9b4704d576fc0ee2a16b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
#include <iostream>
#include <ntqstring.h>
#include <ntqfile.h>
#include <ntqfileinfo.h>
#include <ntqdir.h>
#include <math.h>

enum E { red, green, blue, yellow };
struct S { int x, y; S* s; };

struct emptyBase { };
struct emptyDerived : S { };
struct emptyNested : emptyBase { };
struct emptyVBase { virtual ~emptyVBase(){} };
struct emptyVDerived : S { virtual ~emptyVDerived(){} };
struct emptyVNested : emptyVBase { };

int globalvar = 1234;

class Cl
{
	int k;
	double l;
public:
	Cl(int r);
	virtual ~Cl();
	virtual int f(int x);
};

typedef void (*PtrFunc)(E*, char);

class Dl : public Cl
{
public:
	Dl(int r);
	virtual int f(int x);
	int operator()(const TQString& x, int& y) const;
	operator const char*() { return 0; }
	operator PtrFunc*();
};

namespace A {
namespace {
namespace B {
namespace {
namespace {
void g()
{
	S s1, s2;
	s1.x = 85;
	s2.y = 17;
	s1.s = &s2;
	s2.s = &s1;
}
} // namespace
void Banong() { g(); }
} // namespace
void g() { Banong(); }
} // namespace B
void Aanong() { B::g(); }
} // namespace
void g() { Aanong(); }
} // namespace A

void f(E e[3], char c)
{
	E x = e[2];
	S y[2];
	E* pe = e;
        E* pea[3] = { pe, };
	{
		int x = 17;
		x;
	}
	A::g();
	char buffer[300];
	memset(buffer, 1, 300);
	for (int i = 0; i < sizeof(buffer); i +=15) buffer[i] = '\02';
	TQDir dir;
	TQFile file;
	TQFileInfo fi;
	x = red;
	emptyBase eb;
	emptyDerived ed;
	emptyNested en;
	int ea[3];
	emptyVBase evb;
	emptyVDerived evd;
	emptyVNested evn;
}

void strtest(const char* t)
{
    const char* s = t;
    const char*& s2 = s;
    if (t == 0)
	strtest(s2);
    std::cout << s2 << std::endl;
}

template<typename F>
void templated_strtest(F f, const char* t)
{
	// test <incomplete sequence> in various contexts
	struct incomplete_seq_intern {
		int val;
		char is[4];
		int val2;
	};
	struct incomplete_seq_end {
		int val;
		char is[4];
	};
	unsigned char a[4] = {',', 020, 021, 0325};
	incomplete_seq_intern b = { 1, {',', 020, 021, 0325}, 2 };
	incomplete_seq_end c = { 1, {',', 020, 021, 0325} };
	unsigned char d[30][4] = { {',', 020, 021, 0325}, };
	for (int i = 1; i < 30; i++)
		memcpy(d[i], d[0], 4);
	incomplete_seq_intern ba[30] = { { 1, {',', 020, 021, 0325}, 2 } };
	incomplete_seq_end ca[30] = { { 1, {',', 020, 021, 0325} } };

	f(t);
}

void segFault()
{
	*(char*)0 = 's';
}

int main(int argc, char* argv[])
{
	if (argc > 1) {
		if (*argv[1] == 's') {
			segFault();
		} else if (*argv[1] == 'a') {
			// let debugger attach
			int junk;
			std::cin >> junk;
		}
	}

	char a[6] = { 'a', 'B', '\'', '\"' };
	char a1[1] = { '1' };
	E e[3] = { red, green, blue };
	E e1[1] = { yellow };

	a[0] = '5';
       	void (*pf[2])(E*, char) = {f};
	{
		double d[1] = { -1.234e123 };
		int i = 10;
		sin(i);
	}
	(*pf[0])(e, '\n');

	TQString s;

	s = "Hi, there!\r\n\t\"\'\\";

	const TQString& strref = s;

	templated_strtest(strtest, s);
	s = "asbcxxxxxxxxxxxxxxxxxxxxxxxxxxx";
	strtest(s);
	s += "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiii";
	strtest(s);
	s += "rst";
	strtest(s);
	s = "xxxxxxxxxxxxxxxxxxxxxxxxxxx";
	strtest(s);
	s += "rst";
	strtest(s);
	s = "";

	Cl c1(13);
	Dl d1(3214);
	d1.f(17);
	int n = 83;
	d1(strref, n);
	PtrFunc* ppf = d1;
}

Cl::Cl(int r) :
	k(r),
	l(sin(r))
{
    std::cout << l << std::endl;
}

Cl::~Cl()
{
}

int Cl::f(int x)
{
	int y = 2*x;
	return y;
}

Dl::Dl(int r) :
	Cl(r)
{
}

int Dl::f(int x)
{
	int y = Cl::f(x);
	return y+3;
}

int Dl::operator()(const TQString& x, int& y) const
{
	std::cerr << "ha! I know!" << std::endl;
	return 1;
}

Dl::operator PtrFunc*()
{
    return 0;
}