2004-09-13 Andrew MacLeod <amacleod@redhat.com>
* g++.dg/tree-ssa/pr17400.C: New testcase.
From-SVN: r87449
+2004-09-13 Andrew MacLeod <amacleod@redhat.com>
+
+ * g++.dg/tree-ssa/pr17400.C: New testcase.
+
2004-09-13 James E Wilson <wilson@specifixinc.com>
* gcc.target/mips/sb1-1.c: New testcase.
--- /dev/null
+// Test PR 17400. Test case provided by Serge Belyshev.
+
+/* { dg-do compile } */
+/* { dg-options "-O1" } */
+
+
+void inc (int &);
+bool dec_test (int &);
+
+struct A
+{
+ int c;
+
+ friend void AddRef (A * p)
+ {
+ inc (p->c);
+ }
+
+ friend void Release (A * p)
+ {
+ if(dec_test (p->c))
+ delete p;
+ }
+};
+
+struct B
+{
+ B (A *p) : obj(p)
+ {
+ AddRef (obj);
+ }
+
+ ~B()
+ {
+ Release (obj);
+ }
+
+ void swap (B &rhs)
+ {
+ A * tmp = obj;
+ obj = rhs.obj;
+ rhs.obj = tmp;
+ }
+
+ A *obj;
+};
+
+void bar (A *p1, A* p2)
+{
+ B px (p1);
+ B px2 (p2);
+ px.swap (px2);
+}