reference, declarationdefinition
definition → references, declarations, derived classes, virtual overrides
reference to multiple definitions → definitions
unreferenced
    1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53
   54
   55
   56
   57
   58
   59
   60
   61
   62
   63
   64
   65
   66
   67
   68
   69
   70
   71
   72
   73
   74
   75
   76
   77
   78
   79
   80
   81
   82
   83
   84
   85
   86
   87
   88
   89
   90
   91
   92
   93
   94
   95
   96
   97
   98
   99
  100
  101
  102
  103
  104
  105
  106
  107
  108
  109
  110
  111
  112
  113
  114
  115
  116
  117
// RUN: %clang_cc1 -fsyntax-only -verify %s

// C++98 [class.friend]p7:
// C++11 [class.friend]p9:
//   A name nominated by a friend declaration shall be accessible in
//   the scope of the class containing the friend declaration.

// PR12328
// Simple, non-templated case.
namespace test0 {
  class X {
    void f(); // expected-note {{implicitly declared private here}}
  };

  class Y {
    friend void X::f(); // expected-error {{friend function 'f' is a private member of 'test0::X'}}
  };
}

// Templated but non-dependent.
namespace test1 {
  class X {
    void f(); // expected-note {{implicitly declared private here}}
  };

  template <class T> class Y {
    friend void X::f(); // expected-error {{friend function 'f' is a private member of 'test1::X'}}
  };
}

// Dependent but instantiated at the right type.
namespace test2 {
  template <class T> class Y;

  class X {
    void f();
    friend class Y<int>;
  };

  template <class T> class Y {
    friend void X::f();
  };

  template class Y<int>;
}

// Dependent and instantiated at the wrong type.
namespace test3 {
  template <class T> class Y;

  class X {
    void f(); // expected-note {{implicitly declared private here}}
    friend class Y<int>;
  };

  template <class T> class Y {
    friend void X::f(); // expected-error {{friend function 'f' is a private member of 'test3::X'}}
  };

  template class Y<float>; // expected-note {{in instantiation}}
}

// Dependent because dependently-scoped.
namespace test4 {
  template <class T> class X {
    void f();
  };

  template <class T> class Y {
    friend void X<T>::f();
  };
}

// Dependently-scoped, no friends.
namespace test5 {
  template <class T> class X {
    void f(); // expected-note {{implicitly declared private here}}
  };

  template <class T> class Y {
    friend void X<T>::f(); // expected-error {{friend function 'f' is a private member of 'test5::X<int>'}}
  };

  template class Y<int>; // expected-note {{in instantiation}}
}

// Dependently-scoped, wrong friend.
namespace test6 {
  template <class T> class Y;

  template <class T> class X {
    void f(); // expected-note {{implicitly declared private here}}
    friend class Y<float>;
  };

  template <class T> class Y {
    friend void X<T>::f(); // expected-error {{friend function 'f' is a private member of 'test6::X<int>'}}
  };

  template class Y<int>; // expected-note {{in instantiation}}
}

// Dependently-scoped, right friend.
namespace test7 {
  template <class T> class Y;

  template <class T> class X {
    void f();
    friend class Y<int>;
  };

  template <class T> class Y {
    friend void X<T>::f();
  };

  template class Y<int>;
}