1 extern "C" int printf (const char *, ...);
2 
3 int c, d;
4 class Foo
5 {
6 public:
Foo()7    Foo() { printf("Foo() 0x%08lx\n", (__SIZE_TYPE__)this); ++c; }
Foo(Foo const &)8    Foo(Foo const &) { printf("Foo(Foo const &) 0x%08lx\n", (__SIZE_TYPE__)this); }
~Foo()9    ~Foo() { printf("~Foo() 0x%08lx\n", (__SIZE_TYPE__)this); ++d; }
10 };
11 
12 // Bar creates constructs a temporary Foo() as a default
13 class Bar
14 {
15 public:
16    Bar(Foo const & = Foo()) { printf("Bar(Foo const &) 0x%08lx\n", (__SIZE_TYPE__)this); }
17 };
18 
fakeRef(Bar *)19 void fakeRef(Bar *)
20 {
21 }
22 
main()23 int 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 }
41