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 15class Object { 16public: 17 Object(); 18 Object(const Object&); 19 ~Object(); 20 21 void OK() const; 22private: 23 bool _destructed; 24}; 25 26class Char: public Object { 27public: 28 Char(); 29 Char(char); 30 Char(const Char&); 31 ~Char(); 32 33 operator char () const; 34private: 35 char _c; 36}; 37 38int main() 39{ 40 Char r, s; 41 42 r = Char('r'); 43 s = Char('s'); 44} 45 46// 47// Object stuff 48// 49Object::Object(): 50_destructed(FALSE) 51{} 52 53Object::Object(const Object& other): 54_destructed(FALSE) 55{ 56 other.OK(); 57} 58 59Object::~Object() 60{ 61 OK(); 62 _destructed = TRUE; 63} 64 65void 66Object::OK() const 67{ 68 if (_destructed) { 69 std::cerr << "FAILURE - reference was made to a destructed object\n"; 70 std::abort(); 71 } 72} 73 74// 75// Char stuff 76// 77 78Char::Char(): 79Object(), 80_c('a') 81{ } 82 83Char::Char(char c): 84Object(), 85_c(c) 86{ } 87 88Char::Char(const Char& other): 89Object(other), 90_c(other._c) 91{ } 92 93Char::~Char() 94{ 95 OK(); 96} 97 98Char::operator char () const 99{ 100 return _c; 101} 102 103 104