source: trunk/src/gcc/gcc/testsuite/g++.old-deja/g++.other/temporary1.C@ 2

Last change on this file since 2 was 2, checked in by bird, 22 years ago

Initial revision

  • Property cvs2svn:cvs-rev set to 1.1
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 991 bytes
Line 
1extern "C" int printf (const char *, ...);
2
3int c, d;
4class Foo
5{
6public:
7 Foo() { printf("Foo() 0x%08lx\n", (__SIZE_TYPE__)this); ++c; }
8 Foo(Foo const &) { printf("Foo(Foo const &) 0x%08lx\n", (__SIZE_TYPE__)this); }
9 ~Foo() { printf("~Foo() 0x%08lx\n", (__SIZE_TYPE__)this); ++d; }
10};
11
12// Bar creates constructs a temporary Foo() as a default
13class Bar
14{
15public:
16 Bar(Foo const & = Foo()) { printf("Bar(Foo const &) 0x%08lx\n", (__SIZE_TYPE__)this); }
17};
18
19void fakeRef(Bar *)
20{
21}
22
23int main()
24{
25 // Create array of Bar. Will use default argument on constructor.
26 // The old compiler will loop constructing Bar. Each loop will
27 // construct a temporary Foo() but will not destruct the Foo().
28 // The Foo() temporary is destructed only once after the loop
29 // completes. This could lead to a memory leak if the constructor
30 // of Foo() allocates memory.
31 Bar bar[2];
32
33 fakeRef(bar);
34
35 printf("Done\n");
36
37 if (c == d && c == 2)
38 return 0;
39 return 1;
40}
Note: See TracBrowser for help on using the repository browser.