xref: /aosp_15_r20/external/clang/test/SemaTemplate/friend.cpp (revision 67e74705e28f6214e480b399dd47ea732279e315)
1*67e74705SXin Li // RUN: %clang_cc1 -fsyntax-only -verify %s
2*67e74705SXin Li template<typename T> struct A {
3*67e74705SXin Li   struct B { };
4*67e74705SXin Li 
5*67e74705SXin Li   friend struct B;
6*67e74705SXin Li };
7*67e74705SXin Li 
f()8*67e74705SXin Li void f() {
9*67e74705SXin Li   A<int>::B b;
10*67e74705SXin Li }
11*67e74705SXin Li 
12*67e74705SXin Li struct C0 {
13*67e74705SXin Li   friend struct A<int>;
14*67e74705SXin Li };
15*67e74705SXin Li 
16*67e74705SXin Li namespace PR6770 {
17*67e74705SXin Li   namespace N {
18*67e74705SXin Li     int f1(int);
19*67e74705SXin Li   }
20*67e74705SXin Li   using namespace N;
21*67e74705SXin Li 
22*67e74705SXin Li   namespace M {
23*67e74705SXin Li     float f1(float);
24*67e74705SXin Li   }
25*67e74705SXin Li   using M::f1;
26*67e74705SXin Li 
27*67e74705SXin Li   template<typename T> void f1(T, T);
28*67e74705SXin Li   template <class T>
f()29*67e74705SXin Li   void f() {
30*67e74705SXin Li     friend class f; // expected-error{{'friend' used outside of class}}
31*67e74705SXin Li     friend class f1; // expected-error{{'friend' used outside of class}}
32*67e74705SXin Li   }
33*67e74705SXin Li }
34*67e74705SXin Li 
35*67e74705SXin Li namespace friend_redecl_inline {
36*67e74705SXin Li // We had a bug where instantiating the foo friend declaration would check the
37*67e74705SXin Li // defined-ness of the most recent decl while checking if the canonical decl was
38*67e74705SXin Li // inlined.
39*67e74705SXin Li void foo();
40*67e74705SXin Li void bar();
41*67e74705SXin Li template <typename T>
42*67e74705SXin Li class C {
43*67e74705SXin Li   friend void foo();
44*67e74705SXin Li   friend inline void bar();
45*67e74705SXin Li };
foo()46*67e74705SXin Li inline void foo() {}
bar()47*67e74705SXin Li inline void bar() {}
48*67e74705SXin Li C<int> c;
49*67e74705SXin Li }
50