1 // { dg-do run  }
2 extern "C" int printf (const char *, ...);
3 
4 int c, d;
5 class Foo
6 {
7 public:
Foo()8    Foo() { printf("Foo() 0x%08lx\n", (__SIZE_TYPE__)this); ++c; }
Foo(Foo const &)9    Foo(Foo const &) { printf("Foo(Foo const &) 0x%08lx\n", (__SIZE_TYPE__)this); }
~Foo()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 
fakeRef(Bar *)20 void fakeRef(Bar *)
21 {
22 }
23 
main()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 }
42