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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [gcc/] [testsuite/] [g++.old-deja/] [g++.other/] [temporary1.C] - Blame information for rev 749

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 699 jeremybenn
// { dg-do run  }
2
extern "C" int printf (const char *, ...);
3
 
4
int c, d;
5
class Foo
6
{
7
public:
8
   Foo() { printf("Foo() 0x%08lx\n", (__SIZE_TYPE__)this); ++c; }
9
   Foo(Foo const &) { printf("Foo(Foo const &) 0x%08lx\n", (__SIZE_TYPE__)this); }
10
   ~Foo() { printf("~Foo() 0x%08lx\n", (__SIZE_TYPE__)this); ++d; }
11
};
12
 
13
// Bar creates constructs a temporary Foo() as a default
14
class Bar
15
{
16
public:
17
   Bar(Foo const & = Foo()) { printf("Bar(Foo const &) 0x%08lx\n", (__SIZE_TYPE__)this); }
18
};
19
 
20
void fakeRef(Bar *)
21
{
22
}
23
 
24
int main()
25
{
26
   // Create array of Bar. Will use default argument on constructor.
27
   // The old compiler will loop constructing Bar. Each loop will
28
   // construct a temporary Foo() but will not destruct the Foo().
29
   // The Foo() temporary is destructed only once after the loop
30
   // completes. This could lead to a memory leak if the constructor
31
   // of Foo() allocates memory.
32
   Bar bar[2];
33
 
34
   fakeRef(bar);
35
 
36
   printf("Done\n");
37
 
38
   if (c == d && c == 2)
39
     return 0;
40
   return 1;
41
}

powered by: WebSVN 2.1.0

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