summaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.old-deja/g++.brendan/crash47.C
diff options
context:
space:
mode:
authorupstream source tree <ports@midipix.org>2015-03-15 20:14:05 -0400
committerupstream source tree <ports@midipix.org>2015-03-15 20:14:05 -0400
commit554fd8c5195424bdbcabf5de30fdc183aba391bd (patch)
tree976dc5ab7fddf506dadce60ae936f43f58787092 /gcc/testsuite/g++.old-deja/g++.brendan/crash47.C
downloadcbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.bz2
cbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.xz
obtained gcc-4.6.4.tar.bz2 from upstream website;upstream
verified gcc-4.6.4.tar.bz2.sig; imported gcc-4.6.4 source tree from verified upstream tarball. downloading a git-generated archive based on the 'upstream' tag should provide you with a source tree that is binary identical to the one extracted from the above tarball. if you have obtained the source via the command 'git clone', however, do note that line-endings of files in your working directory might differ from line-endings of the respective files in the upstream repository.
Diffstat (limited to 'gcc/testsuite/g++.old-deja/g++.brendan/crash47.C')
-rw-r--r--gcc/testsuite/g++.old-deja/g++.brendan/crash47.C94
1 files changed, 94 insertions, 0 deletions
diff --git a/gcc/testsuite/g++.old-deja/g++.brendan/crash47.C b/gcc/testsuite/g++.old-deja/g++.brendan/crash47.C
new file mode 100644
index 000000000..3afa5fa99
--- /dev/null
+++ b/gcc/testsuite/g++.old-deja/g++.brendan/crash47.C
@@ -0,0 +1,94 @@
+// { dg-do assemble }
+// GROUPS passed old-abort
+const int TRUE = 1;
+const int FALSE = 0;
+
+class Rep {
+protected:
+ Rep(): count(0)
+ { }
+ Rep(const Rep& other): count(0)
+ { }
+
+ Rep& operator=(const Rep& other)
+ { /* DO NOT copy over other.count */
+ return *this; }
+
+public: // TODO - for now
+ // Because it is to hard to restrict these operations to the descendants
+ // of Rep<REP> that we haven't named yet. So we just make them public.
+ void inc()
+ { count++; }
+ void dec()
+ { if (0 == --count) delete this; }
+private:
+ unsigned count;
+};
+
+template<class REP>
+class Ref {
+public:
+ Ref(): rep(0)
+ { }
+ Ref(const Ref<REP>& other): rep(other.rep)
+ { if (rep) rep->inc(); }
+ ~Ref()
+ { if (rep) rep->dec();
+ rep = 0; }
+
+ Ref<REP>& operator=(const Ref<REP>& other)
+ { if (rep != other.rep) {
+ if (rep) rep->dec();
+ rep = other.rep;
+ if (rep) rep->inc(); }
+ return *this; }
+
+ bool null() const
+ { return 0 == rep ? TRUE: FALSE; }
+ bool valid() const
+ { return 0 != rep ? TRUE: FALSE; }
+
+ REP* operator->() const // should be a valid() reference
+ { return rep; }
+ operator REP*() const; // should be a valid() reference
+
+protected:
+ REP *rep;
+
+ Ref(REP *r): rep(r)
+ { if (rep) rep->inc(); }
+
+ Ref<REP>& operator=(REP *r)
+ { if (rep != r) {
+ if (rep) rep->dec();
+ rep = r;
+ if (rep) rep->inc(); }
+ return *this; }
+};
+
+template<class REP>
+Ref<REP>::operator REP*() const // should be a valid() reference
+{ return rep; }
+
+template<class REP>
+inline int
+operator==(const Ref<REP>& a, const Ref<REP>& b)
+{ return (REP *) a == (REP *) b; }
+
+template<class REP>
+inline int
+operator!=(const Ref<REP>& a, const Ref<REP>& b)
+{ return (REP *) a != (REP *) b; }
+
+class XRep: public Rep {
+public:
+ int i;
+};
+
+int
+main()
+{
+ Ref<XRep> y;
+
+ return y != y;
+}