blob: d60d43ea95c2bfd9c2389f571ec0a3c7698c2332 (
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
|
// { dg-do run }
// { dg-options "-w" }
// Copyright (C) 1999, 2000 Free Software Foundation, Inc.
// Contributed by Nathan Sidwell 29 Aug 1999 <nathan@acm.org>
// We cannot catch an ambiguous base class.
// -- public, << private, == virtual
// E==D--B==A
// +--C==A
// +--AA-A
struct A { int m; };
struct B : virtual A { int m; };
struct C : virtual A { int m; };
struct AA : A { int m; };
struct D : B, C, AA { int m; };
struct E : virtual D { int m; };
void fna(A *obj) { throw obj; }
void fnb(B *obj) { throw obj; }
void fnc(C *obj) { throw obj; }
void fnd(D *obj) { throw obj; }
void fnaa(AA *obj) { throw obj; }
void fne(E *obj) { throw obj; }
extern "C" void abort();
void check(E *e)
{
int caught;
// try with whole object
caught = 0;
try { fne(e); }
catch(A *p) { abort(); } // A is ambiguous
catch(D *p) { caught = 1; if (p != e) abort();}
catch(...) { abort(); }
if (!caught) abort();
caught = 0;
try { fne(e); }
catch(A *p) { abort(); } // A is ambiguous
catch(B *p) { caught = 1; if (p != e) abort();}
catch(...) { abort(); }
if (!caught) abort();
caught = 0;
try { fne(e); }
catch(A *p) { abort(); } // A is ambiguous
catch(C *p) { caught = 1; if (p != e) abort();}
catch(...) { abort(); }
if (!caught) abort();
caught = 0;
try { fne(e); }
catch(A *p) { abort(); } // A is ambiguous
catch(AA *p) { caught = 1; if (p != e) abort();}
catch(...) { abort(); }
if (!caught) abort();
// try with D oject
caught = 0;
try { fnd((D *)e); }
catch(A *p) { abort(); } // A is ambiguous
catch(D *p) { caught = 1; if (p != e) abort();}
catch(...) { abort(); }
if (!caught) abort();
caught = 0;
try { fnd((D *)e); }
catch(A *p) { abort(); } // A is ambiguous
catch(B *p) { caught = 1; if (p != e) abort();}
catch(...) { abort(); }
if (!caught) abort();
caught = 0;
try { fnd((D *)e); }
catch(A *p) { abort(); } // A is ambiguous
catch(C *p) { caught = 1; if (p != e) abort();}
catch(...) { abort(); }
if (!caught) abort();
caught = 0;
try { fnd((D *)e); }
catch(A *p) { abort(); } // A is ambiguous
catch(AA *p) { caught = 1; if (p != e) abort();}
catch(...) { abort(); }
if (!caught) abort();
// try with an A object
caught = 0;
try { fna((B *)e); }
catch(B *p) { abort(); } // throw type is static type
catch(A *p) { caught = 1; if (p != (B *)e) abort();}
catch(...) { abort(); }
if (!caught) abort();
caught = 0;
try { fna((C *)e); }
catch(C *p) { abort(); } // throw type is static type
catch(A *p) { caught = 1; if (p != (C *)e) abort();}
catch(...) { abort(); }
if (!caught) abort();
caught = 0;
try { fna((AA *)e); }
catch(AA *p) { abort(); } // throw type is static type
catch(A *p) { caught = 1; if (p != (AA *)e) abort();}
catch(...) { abort(); }
if (!caught) abort();
// try with B object
caught = 0;
try { fnb((B *)e); }
catch(A *p) { caught = 1; if (p != (B *)e) abort();}
catch(...) { abort(); }
if (!caught) abort();
caught = 0;
try { fnb((B *)e); }
catch(B *p) { caught = 1; if (p != e) abort();}
catch(...) { abort(); }
if (!caught) abort();
caught = 0;
try { fnb((B *)e); }
catch(C *p) { abort(); }
catch(D *p) { abort(); }
catch(...) { caught =1; }
if (!caught) abort();
// try with C object
caught = 0;
try { fnc((C *)e); }
catch(A *p) { caught = 1; if (p != (C *)e) abort();}
catch(...) { abort(); }
if (!caught) abort();
caught = 0;
try { fnc((C *)e); }
catch(C *p) { caught = 1; if (p != e) abort();}
catch(...) { abort(); }
if (!caught) abort();
caught = 0;
try { fnc((C *)e); }
catch(B *p) { abort(); }
catch(D *p) { abort(); }
catch(...) { caught =1; }
if (!caught) abort();
// try with AA object
caught = 0;
try { fnaa((AA *)e); }
catch(A *p) { caught = 1; if (p != (AA *)e) abort();}
catch(...) { abort(); }
if (!caught) abort();
caught = 0;
try { fnaa((AA *)e); }
catch(AA *p) { caught = 1; if (p != e) abort();}
catch(...) { abort(); }
if (!caught) abort();
caught = 0;
try { fnaa((AA *)e); }
catch(C *p) { abort(); }
catch(B *p) { abort(); }
catch(D *p) { abort(); }
catch(...) { caught =1; }
if (!caught) abort();
return;
}
int main ()
{
E e;
check (&e); // try with an object
check ((E *)0); // try with no object
return 0;
}
|