OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [gcc-4.2.2/] [gcc/] [testsuite/] [g++.dg/] [tree-ssa/] [pr17400.C] - Rev 816

Compare with Previous | Blame | View Log

// 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);
}

Compare with Previous | Blame | View Log

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.