Debian Codegraph @

gcc/testsuite/g++.old-deja/g++.mike/p658.C

raw
1 // { dg-do run }
2 // { dg-skip-if "requires hosted libstdc++ for iostream" { ! hostedlib } }
3 // prms-id: 658
4
5 #include <iostream>
6 #include <cstdlib>
7
8 /* We may not find the libg++ <bool.h>. */
9 #ifndef FALSE
10 #define FALSE false
11 #endif
12 #ifndef TRUE
13 #define TRUE true
14 #endif
15
16 // The VxWorks headers define a macro named "OK", which is not
17 // ISO-compliant, but is part of the VxWorks API.
18 #if defined __vxworks
19 #undef OK
20 #endif
21
22 class Object {
23 public:
24 Object();
25 Object(const Object&);
26 ~Object();
27
28 void OK() const;
29 private:
30 bool _destructed;
31 };
32
33 class Char: public Object {
34 public:
35 Char();
36 Char(char);
37 Char(const Char&);
38 ~Char();
39
40 operator char () const;
41 private:
42 char _c;
43 };
44
45 int main()
46 {
47 Char r, s;
48
49 r = Char('r');
50 s = Char('s');
51 }
52
53 //
54 // Object stuff
55 //
56 Object::Object():
57 _destructed(FALSE)
58 {}
59
60 Object::Object(const Object& other):
61 _destructed(FALSE)
62 {
63 other.OK();
64 }
65
66 Object::~Object()
67 {
68 OK();
69 _destructed = TRUE;
70 }
71
72 void
73 Object::OK() const
74 {
75 if (_destructed) {
76 std::cerr << "FAILURE - reference was made to a destructed object\n";
77 std::abort();
78 }
79 }
80
81 //
82 // Char stuff
83 //
84
85 Char::Char():
86 Object(),
87 _c('a')
88 { }
89
90 Char::Char(char c):
91 Object(),
92 _c(c)
93 { }
94
95 Char::Char(const Char& other):
96 Object(other),
97 _c(other._c)
98 { }
99
100 Char::~Char()
101 {
102 OK();
103 }
104
105 Char::operator char () const
106 {
107 return _c;
108 }
109
110