1 // { dg-do assemble  }
2 
3 // by Alexandre Oliva <oliva@dcc.unicamp.br>
4 
5 // I'm not 100% sure this program is correct, but g++ shouldn't just
6 // crash.
7 
8 // The idea is to give privileged access to bar<A> only to
9 // specializations foo<A,B>, for all B.
10 
11 template <class A, class B> void foo();
12 template <class C> class bar {
13   int i; // { dg-message "" } private
14   template <class B> friend void foo<C,B>(); // { dg-error "" } bogus declaration
15 };
foo()16 template <class A, class B> void foo() {
17   bar<A> baz; baz.i = 1;   // { dg-error "" } foo cannot access bar<int>::i
18   bar<int> buz; buz.i = 1; // { dg-error "" } foo cannot access bar<int>::i
19 }
main()20 int main() {
21   foo<void,void>();
22   foo<int,void>();
23 }
24