Debian Codegraph @

gcc/testsuite/g++.old-deja/g++.other/friend4.C

raw
1 // { dg-do assemble }
2
3 // by Alexandre Oliva <[email protected]>
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 "34:invalid use of template-id" }
15 };
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 }
20 int main() {
21 foo<void,void>();
22 foo<int,void>();
23 }