summaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/tree-ssa/pr17400.C
blob: a6619a84fd3f772435c35c06e70bce1f394115db (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// 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);
}