2008-05-30 Vladimir Makarov <vmakarov@redhat.com>
[official-gcc.git] / gcc / testsuite / g++.old-deja / g++.mike / p658.C
blob8fc7cd51b2be34c13f759f3fc80247665a6fd157
1 // { dg-do run  }
2 // prms-id: 658
4 #include <iostream>
5 #include <cstdlib>
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
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
21 class Object {
22 public:
23     Object();
24     Object(const Object&);
25     ~Object();
27     void OK() const;
28 private:
29     bool _destructed;
32 class Char: public Object {
33 public:
34     Char();
35     Char(char);
36     Char(const Char&);
37     ~Char();
39     operator char () const;
40 private:
41     char _c;
44 int main()
46     Char r, s;
48     r = Char('r');
49     s = Char('s');
53 // Object stuff
55 Object::Object():
56 _destructed(FALSE)
59 Object::Object(const Object& other):
60 _destructed(FALSE)
62     other.OK();
65 Object::~Object()
67     OK();
68     _destructed = TRUE;
71 void
72 Object::OK() const
74     if (_destructed) {
75         std::cerr << "FAILURE - reference was made to a destructed object\n";
76         std::abort();
77     }
81 // Char stuff
84 Char::Char():
85 Object(),
86 _c('a')
87 { }
89 Char::Char(char c):
90 Object(),
91 _c(c)
92 { }
94 Char::Char(const Char& other):
95 Object(other),
96 _c(other._c)
97 { }
99 Char::~Char()
101     OK();
104 Char::operator char () const
106     return _c;