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