summaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.old-deja/g++.mike/p2846.C
blob: bce20bb0048849919b9e0cb35d227c5b1aaa77e8 (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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// { dg-do run  }
// prms-id: 2846

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

class A;
class B;

int c;

class A {
public:

  A(void){}
  A(const A&){}
  A(const B&);

  virtual ~A(void){}

  virtual void print(void) const {
    printf("A::print\n");
    printf("FAIL\n");
    exit(1);
  }
  B compute(void) const;
};

class B : private A {
friend class A;
public:

  virtual ~B(void){}

  void print(void) const {
    ++c;
    printf("B::print\n");
  }

private:
  B(const A& x, int){}
};

A::A(const B& s) {
  s.print();
}

B A::compute(void) const {
  B sub(*this, 1);
  return sub;
}

int main ()
{
  A titi;
  A toto = titi.compute();
  if (c != 1)
    {
      printf ("FAIL\n");
      return 1;
    }
  else
    {
      printf("PASS\n");
      return 0;
    }
}