Debian Codegraph @

gcc/testsuite/g++.dg/tc1/dr166.C

raw
1 // { dg-do compile }
2 // Origin: Giovanni Bajo <giovannibajo at gcc dot gnu dot org>
3 // DR166: Friend declarations of template-ids
4
5 namespace N {
6 template <class T> void f(T);
7 void g();
8
9 namespace M {
10 class A {
11 friend void f<int>(int); // N::f
12 static int x; // { dg-message "private" }
13 };
14
15 class B {
16 template <class T> friend void f(T); // M::f
17 static int x; // { dg-message "private" }
18 };
19
20 class C {
21 friend void g(); // M::g
22 static int x; // { dg-message "private" }
23 };
24
25 template <class T> void f(T) // will be instantiated as f<long>
26 {
27 M::A::x = 0; // { dg-error "within this context" }
28 M::B::x = 0;
29 }
30 template <> void f<int>(int)
31 { M::A::x = 0; } // { dg-error "within this context" }
32 template <> void f<double>(double )
33 {
34 M::B::x = 0;
35 M::f<long>(0); // { dg-message "required" }
36 }
37
38 void g(void)
39 { M::C::x = 0; }
40 }
41
42 template <class T> void f(T) // will be instantiated as f<long>
43 {
44 M::A::x = 0; // { dg-error "within this context" }
45 M::B::x = 0; // { dg-error "within this context" }
46 }
47
48 template <> void f<int>(int )
49 {
50 N::f<long>(0); // { dg-message "required" }
51 M::A::x = 0;
52 M::B::x = 0; // { dg-error "within this context" }
53 }
54
55 template <> void f<char>(char )
56 { M::A::x = 0; } // { dg-error "within this context" }
57
58 void g(void)
59 { M::C::x = 0; } // { dg-error "within this context" }
60 }