2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / gcc / testsuite / g++.dg / template / memfriend7.C
blobaed029500af7e04a6561cecf0ae968c22614a645
1 // { dg-do compile }
3 // Copyright (C) 2003 Free Software Foundation
4 // Contributed by Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net>
6 // Member function of class template as friend
7 // Erroneous case: mismatch during specialization
9 template <class T> struct A {
10   template <class U> void f(U);
11   void g();
12   void h();
13   void i(int);
14   template <T t> void j();
17 class C {
18   int ii;                               // { dg-error "private" }
19   template <class U> template <class V>
20     friend void A<U>::f(V);
21   template <class U> friend void A<U>::g();
22   template <class U> friend void A<U>::h();
23   template <class U> friend void A<U>::i(int);
24   template <class U> template <U t>
25     friend void A<U>::j();
28 template <class T> struct A<T*> {
29   void f(int);
30   template <class U> void g();
31   int h();
32   void i(char);
33   template <int> void j();
36 template <class T> void A<T*>::f(int)
38   C c;
39   c.ii = 0;                             // { dg-error "context" }
42 template <class T> template <class U> void A<T*>::g()
44   C c;
45   c.ii = 0;                             // { dg-error "context" }
48 template <class T> int A<T*>::h()
50   C c;
51   c.ii = 0;                             // { dg-error "context" }
54 template <class T> void A<T*>::i(char)
56   C c;
57   c.ii = 0;                             // { dg-error "context" }
60 template <class T> template <int> void A<T*>::j()
62   C c;
63   c.ii = 0;                             // { dg-error "context" }
66 template <> struct A<char> {
67   void f(int);
68   template <class U> void g();
69   int h();
70   void i(char);
71   template <int> void j();
74 void A<char>::f(int)
76   C c;
77   c.ii = 0;                             // { dg-error "context" }
80 template <class U> void A<char>::g()
82   C c;
83   c.ii = 0;                             // { dg-error "context" }
86 template <> void A<char>::g<int>()
88   C c;
89   c.ii = 0;                             // { dg-error "context" }
92 int A<char>::h()
94   C c;
95   c.ii = 0;                             // { dg-error "context" }
98 void A<char>::i(char)
100   C c;
101   c.ii = 0;                             // { dg-error "context" }
104 template <int> void A<char>::j()
106   C c;
107   c.ii = 0;                             // { dg-error "context" }
110 template <> void A<char>::j<0>()
112   C c;
113   c.ii = 0;                             // { dg-error "context" }
116 int main()
118   A<int *> a1;
119   a1.f(0);                              // { dg-error "instantiated" }
120   a1.g<char>();                         // { dg-error "instantiated" }
121   a1.g<int>();                          // { dg-error "instantiated" }
122   a1.h();                               // { dg-error "instantiated" }
123   a1.i('a');                            // { dg-error "instantiated" }
124   a1.j<1>();                            // { dg-error "instantiated" }
125   A<char> a2;
126   a2.f(0);
127   a2.g<char>();                         // { dg-error "instantiated" }
128   a2.g<int>();
129   a2.h();
130   a2.i('a');
131   a2.j<1>();                            // { dg-error "instantiated" }
132   a2.j<0>();