2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / gcc / testsuite / g++.old-deja / g++.brendan / crash47.C
blob3afa5fa994df1169b84b49e3e575c8d802d87789
1 // { dg-do assemble  }
2 // GROUPS passed old-abort
3 const int TRUE = 1;
4 const int FALSE = 0;
6 class Rep {
7 protected:
8     Rep(): count(0)
9         { }
10     Rep(const Rep& other): count(0)
11         { }
13     Rep& operator=(const Rep& other)
14         { /* DO NOT copy over other.count */
15           return *this; }
17 public:         // TODO - for now
18     // Because it is to hard to restrict these operations to the descendants
19     // of Rep<REP> that we haven't named yet.  So we just make them public.
20     void inc()
21         { count++; }
22     void dec()
23         { if (0 == --count) delete this; }
24 private:
25     unsigned count;
28 template<class REP>
29 class Ref {
30 public:
31     Ref(): rep(0)
32         { }
33     Ref(const Ref<REP>& other): rep(other.rep)
34         { if (rep) rep->inc(); }
35     ~Ref()
36         { if (rep) rep->dec();
37           rep = 0; }
39     Ref<REP>& operator=(const Ref<REP>& other)
40         { if (rep != other.rep) {
41             if (rep) rep->dec();
42             rep = other.rep;
43             if (rep) rep->inc(); }
44           return *this; }
46     bool null() const
47         { return 0 == rep ? TRUE: FALSE; }
48     bool valid() const
49         { return 0 != rep ? TRUE: FALSE; }
51     REP* operator->() const             // should be a valid() reference
52         { return rep; }
53     operator REP*() const;              // should be a valid() reference
55 protected:
56     REP *rep;
58     Ref(REP *r): rep(r)
59         { if (rep) rep->inc(); }
61     Ref<REP>& operator=(REP *r)
62         { if (rep != r) {
63             if (rep) rep->dec();
64             rep = r;
65             if (rep) rep->inc(); }
66           return *this; }
69 template<class REP>
70 Ref<REP>::operator REP*() const         // should be a valid() reference
71 { return rep; }
73 template<class REP> 
74 inline int
75 operator==(const Ref<REP>& a, const Ref<REP>& b)
76 { return (REP *) a == (REP *) b; }
78 template<class REP> 
79 inline int
80 operator!=(const Ref<REP>& a, const Ref<REP>& b)
81 { return (REP *) a != (REP *) b; }
83 class XRep: public Rep {
84 public:
85     int i;
88 int
89 main()
91     Ref<XRep> y;
93     return y != y;