| 1 |
// { dg-do compile } |
| 2 |
// Test that template friends referring to class template members are |
| 3 |
// respected. |
| 4 |
|
| 5 |
|
| 6 |
template <class T> struct A |
| 7 |
{ |
| 8 |
int f (T); |
| 9 |
struct AI { |
| 10 |
int f (T); |
| 11 |
}; |
| 12 |
}; |
| 13 |
|
| 14 |
class B |
| 15 |
{ |
| 16 |
template <class T> friend int A<T>::f (T); |
| 17 |
template <class T> friend struct A<T>::AI; |
| 18 |
int a; |
| 19 |
public: |
| 20 |
B(): a(0) { } |
| 21 |
}; |
| 22 |
|
| 23 |
template <class T> int A<T>::f (T) |
| 24 |
{ |
| 25 |
B b; |
| 26 |
return b.a; |
| 27 |
} |
| 28 |
|
| 29 |
template <class T> int A<T>::AI::f (T) |
| 30 |
{ |
| 31 |
B b; |
| 32 |
return b.a; |
| 33 |
} |
| 34 |
|
| 35 |
int main () |
| 36 |
{ |
| 37 |
A<int> a; |
| 38 |
A<int>::AI ai; |
| 39 |
|
| 40 |
int r = a.f (0); |
| 41 |
r |= ai.f (0); |
| 42 |
|
| 43 |
return r; |
| 44 |
} |