OSDN Git Service

fix
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / g++.old-deja / g++.other / friend1.C
1 // Build don't link:
2 // f() should be able to access B::j, as of FDIS [class.protected]/1
3
4 // Subject: Re: [bug] Inheritance and friend access control broken
5 // References: <199803032141.WAA09332@piano.dptmaths.ens-cachan.fr>
6 // <orhg5ff544.fsf@iguacu.dcc.unicamp.br>
7 // <199803041125.MAA06937@cor.dptmaths.ens-cachan.fr>
8 // <orn2f6ek92.fsf@iguacu.dcc.unicamp.br> <19980304102900.46897@dgii.com>
9 // From: Alexandre Oliva <oliva@dcc.unicamp.br>
10 // Date: 06 Mar 1998 01:43:18 -0300
11
12 template <int*>
13 class X {};
14
15 template <typename T>
16 void g();
17
18 struct S;
19
20 template <typename T>
21 struct R;
22
23 class B {
24 protected:
25   int i; // ERROR - in this context
26   static int j;
27 };
28
29 class D : public B {
30   friend void f();
31   template <typename T>
32   friend void g();
33   friend struct S;
34   template <typename T>
35   friend struct R;
36 };
37
38 struct S {
39   void h();
40   X<&B::j> x;
41 };
42
43 template <typename T>
44 struct R {
45   void h();
46   X<&B::j> x;
47 };
48
49 void f()
50 {
51     ((B*)0)->i = 3; // ERROR - protected
52     ((D*)0)->i = 4;
53     B::j = 5;
54     D::j = 6;
55 }
56
57 template <typename T>
58 void g()
59 {
60     ((B*)0)->i = 3; // ERROR - protected
61     ((D*)0)->i = 4;
62     B::j = 5;
63     D::j = 6;
64 }
65
66 template void g<int>();
67
68 void S::h()
69 {
70   ((B*)0)->i = 3; // ERROR - protected
71   ((D*)0)->i = 4;
72   B::j = 5;
73   D::j = 6;
74 }
75
76 template <typename T>
77 void R<T>::h() 
78 {
79   ((B*)0)->i = 3; // ERROR - protected
80   ((D*)0)->i = 4;
81   B::j = 5;
82   D::j = 6;
83 }
84
85 template struct R<double>;