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

Subversion Repositories openrisc

[/] [openrisc/] [tags/] [gnu-src/] [gcc-4.5.1/] [gcc-4.5.1-or32-1.0rc1/] [gcc/] [testsuite/] [g++.old-deja/] [g++.other/] [temporary1.C] - Diff between revs 305 and 338

Only display areas with differences | Details | Blame | View Log

Rev 305 Rev 338
// { dg-do run  }
// { dg-do run  }
extern "C" int printf (const char *, ...);
extern "C" int printf (const char *, ...);
int c, d;
int c, d;
class Foo
class Foo
{
{
public:
public:
   Foo() { printf("Foo() 0x%08lx\n", (__SIZE_TYPE__)this); ++c; }
   Foo() { printf("Foo() 0x%08lx\n", (__SIZE_TYPE__)this); ++c; }
   Foo(Foo const &) { printf("Foo(Foo const &) 0x%08lx\n", (__SIZE_TYPE__)this); }
   Foo(Foo const &) { printf("Foo(Foo const &) 0x%08lx\n", (__SIZE_TYPE__)this); }
   ~Foo() { printf("~Foo() 0x%08lx\n", (__SIZE_TYPE__)this); ++d; }
   ~Foo() { printf("~Foo() 0x%08lx\n", (__SIZE_TYPE__)this); ++d; }
};
};
// Bar creates constructs a temporary Foo() as a default
// Bar creates constructs a temporary Foo() as a default
class Bar
class Bar
{
{
public:
public:
   Bar(Foo const & = Foo()) { printf("Bar(Foo const &) 0x%08lx\n", (__SIZE_TYPE__)this); }
   Bar(Foo const & = Foo()) { printf("Bar(Foo const &) 0x%08lx\n", (__SIZE_TYPE__)this); }
};
};
void fakeRef(Bar *)
void fakeRef(Bar *)
{
{
}
}
int main()
int main()
{
{
   // Create array of Bar. Will use default argument on constructor.
   // Create array of Bar. Will use default argument on constructor.
   // The old compiler will loop constructing Bar. Each loop will
   // The old compiler will loop constructing Bar. Each loop will
   // construct a temporary Foo() but will not destruct the Foo().
   // construct a temporary Foo() but will not destruct the Foo().
   // The Foo() temporary is destructed only once after the loop
   // The Foo() temporary is destructed only once after the loop
   // completes. This could lead to a memory leak if the constructor
   // completes. This could lead to a memory leak if the constructor
   // of Foo() allocates memory.
   // of Foo() allocates memory.
   Bar bar[2];
   Bar bar[2];
   fakeRef(bar);
   fakeRef(bar);
   printf("Done\n");
   printf("Done\n");
   if (c == d && c == 2)
   if (c == d && c == 2)
     return 0;
     return 0;
   return 1;
   return 1;
}
}
 
 

powered by: WebSVN 2.1.0

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