1// { dg-do compile }
2
3// Copyright (C) 2003 Free Software Foundation
4// Contributed by Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net>
5
6// Member function of class template as friend
7// Erroneous case: mismatch during specialization
8
9template <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();
15};
16
17class 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();
26};
27
28template <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();
34};
35
36template <class T> void A<T*>::f(int)
37{
38  C c;
39  c.ii = 0;				// { dg-error "context" }
40}
41
42template <class T> template <class U> void A<T*>::g()
43{
44  C c;
45  c.ii = 0;				// { dg-error "context" }
46}
47
48template <class T> int A<T*>::h()
49{
50  C c;
51  c.ii = 0;				// { dg-error "context" }
52}
53
54template <class T> void A<T*>::i(char)
55{
56  C c;
57  c.ii = 0;				// { dg-error "context" }
58}
59
60template <class T> template <int> void A<T*>::j()
61{
62  C c;
63  c.ii = 0;				// { dg-error "context" }
64}
65
66template <> 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();
72};
73
74void A<char>::f(int)
75{
76  C c;
77  c.ii = 0;				// { dg-error "context" }
78}
79
80template <class U> void A<char>::g()
81{
82  C c;
83  c.ii = 0;				// { dg-error "context" }
84}
85
86template <> void A<char>::g<int>()
87{
88  C c;
89  c.ii = 0;				// { dg-error "context" }
90}
91
92int A<char>::h()
93{
94  C c;
95  c.ii = 0;				// { dg-error "context" }
96}
97
98void A<char>::i(char)
99{
100  C c;
101  c.ii = 0;				// { dg-error "context" }
102}
103
104template <int> void A<char>::j()
105{
106  C c;
107  c.ii = 0;				// { dg-error "context" }
108}
109
110template <> void A<char>::j<0>()
111{
112  C c;
113  c.ii = 0;				// { dg-error "context" }
114}
115
116int main()
117{
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>();
133}
134