blob: c91559645e9ec92e71b0ea38e955baad91e9aadf (
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
|
// { dg-do run }
// GROUPS passed copy-ctors
/*
bad:
sibelius402> a.out
a=5 a.virtMember()=30
BaseClass::Increm --> {i=5, virtMember()=30}
a=7 a.virtMember()=30
b=7 b.virtMember()=30
BaseClass::Increm --> {i=7, virtMember()=999}
b=9 b.virtMember()=30
sibelius403>
good:
sibelius406> a.out
a=5 a.virtMember()=30
BaseClass::Increm --> {i=5, virtMember()=30}
a=7 a.virtMember()=30
b=7 b.virtMember()=30
BaseClass::Increm --> {i=7, virtMember()=30}
b=9 b.virtMember()=30
*/
extern "C" int printf (const char *, ...);
extern "C" void exit (int);
void die () { printf ("FAIL\n"); exit (1); }
class BaseClass {
friend int operator != (const BaseClass irv, int x);
int i;
public:
BaseClass( const BaseClass& ir ) : i(ir.i) {}
BaseClass() : i(5) {}
virtual int virtMember() { return( 999 ); }
void Increm( int r );
};
void BaseClass::Increm( int r )
{
if ((i == 5 && virtMember () == 30)
|| (i == 7 && virtMember () == 30))
i += r;
else
die ();
}
class DerivedClass : public BaseClass {
public:
int virtMember() { return( 30 ); }
};
int operator != (const BaseClass irv, int x) { return irv.i != x; }
int
main ()
{
DerivedClass a;
if (a != 5 || a.virtMember () != 30)
die ();
a.Increm(2);
if (a != 7 || a.virtMember () != 30)
die ();
DerivedClass b = a;
if (b != 7 || a.virtMember () != 30)
die ();
b.Increm(2);
if (b != 9 || a.virtMember () != 30)
die ();
printf ("PASS\n");
}
|