aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/init/array12.C
blob: f45a6e141b76071e9872d73987af5e741b4e8548 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// PR c++/12253
// We should not destroy the temporary A passed to the
// constructor for b[0] before going on to construct b[1].

// { dg-do run }

extern "C" int printf (const char *, ...);

int c;
int r;

struct A
{
  A() { printf ("A()\n"); ++c; }
  A(const A&) { printf ("A(const A&)\n"); ++c; }
  ~A() { printf ("~A()\n"); --c; }
};
 
struct B
{
  B(int i, const A& = A()) {
    printf ("B()\n");
    if (c != i) r = 1;
  }
};
 
int main()
{
  B b[] = { 1, 2 };
  return r;
}