summaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.old-deja/g++.mike/p658.C
blob: 8fc7cd51b2be34c13f759f3fc80247665a6fd157 (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
// { dg-do run  }
// prms-id: 658

#include <iostream>
#include <cstdlib>

/* We may not find the libg++ <bool.h>.  */
#ifndef FALSE
#define FALSE false
#endif
#ifndef TRUE
#define TRUE true
#endif

// The VxWorks kernel-mode headers define a macro named "OK", which is not
// ISO-compliant, but is part of the VxWorks API.
#if defined __vxworks && !defined __RTP__
#undef OK
#endif

class Object {
public:
    Object();
    Object(const Object&);
    ~Object();

    void OK() const;
private:
    bool _destructed;
};

class Char: public Object {
public:
    Char();
    Char(char);
    Char(const Char&);
    ~Char();

    operator char () const;
private:
    char _c;
};

int main()
{
    Char r, s;

    r = Char('r');
    s = Char('s');
}

//
// Object stuff
//
Object::Object():
_destructed(FALSE)
{}

Object::Object(const Object& other):
_destructed(FALSE)
{
    other.OK();
}

Object::~Object()
{
    OK();
    _destructed = TRUE;
}

void
Object::OK() const
{
    if (_destructed) {
	std::cerr << "FAILURE - reference was made to a destructed object\n";
	std::abort();
    }
}

//
// Char stuff
//

Char::Char():
Object(),
_c('a')
{ }

Char::Char(char c):
Object(),
_c(c)
{ }

Char::Char(const Char& other):
Object(other),
_c(other._c)
{ }

Char::~Char()
{
    OK();
}

Char::operator char () const
{
    return _c;
}