head	1.1;
branch	1.1.1;
access;
symbols
	netbsd-11-0-RC4:1.1.1.4
	netbsd-11-0-RC3:1.1.1.4
	netbsd-11-0-RC2:1.1.1.4
	netbsd-11-0-RC1:1.1.1.4
	perseant-exfatfs-base-20250801:1.1.1.4
	netbsd-11:1.1.1.4.0.10
	netbsd-11-base:1.1.1.4
	netbsd-10-1-RELEASE:1.1.1.4
	perseant-exfatfs-base-20240630:1.1.1.4
	perseant-exfatfs:1.1.1.4.0.8
	perseant-exfatfs-base:1.1.1.4
	netbsd-8-3-RELEASE:1.1.1.3
	netbsd-9-4-RELEASE:1.1.1.3
	netbsd-10-0-RELEASE:1.1.1.4
	netbsd-10-0-RC6:1.1.1.4
	netbsd-10-0-RC5:1.1.1.4
	netbsd-10-0-RC4:1.1.1.4
	netbsd-10-0-RC3:1.1.1.4
	netbsd-10-0-RC2:1.1.1.4
	netbsd-10-0-RC1:1.1.1.4
	netbsd-10:1.1.1.4.0.6
	netbsd-10-base:1.1.1.4
	netbsd-9-3-RELEASE:1.1.1.3
	cjep_sun2x:1.1.1.4.0.4
	cjep_sun2x-base:1.1.1.4
	cjep_staticlib_x-base1:1.1.1.4
	netbsd-9-2-RELEASE:1.1.1.3
	cjep_staticlib_x:1.1.1.4.0.2
	cjep_staticlib_x-base:1.1.1.4
	netbsd-9-1-RELEASE:1.1.1.3
	phil-wifi-20200421:1.1.1.4
	phil-wifi-20200411:1.1.1.4
	phil-wifi-20200406:1.1.1.4
	netbsd-8-2-RELEASE:1.1.1.3
	netbsd-9-0-RELEASE:1.1.1.3
	netbsd-9-0-RC2:1.1.1.3
	netbsd-9-0-RC1:1.1.1.3
	netbsd-9:1.1.1.3.0.16
	netbsd-9-base:1.1.1.3
	phil-wifi-20190609:1.1.1.3
	netbsd-8-1-RELEASE:1.1.1.3
	netbsd-8-1-RC1:1.1.1.3
	pgoyette-compat-merge-20190127:1.1.1.3
	pgoyette-compat-20190127:1.1.1.3
	pgoyette-compat-20190118:1.1.1.3
	pgoyette-compat-1226:1.1.1.3
	pgoyette-compat-1126:1.1.1.3
	pgoyette-compat-1020:1.1.1.3
	pgoyette-compat-0930:1.1.1.3
	pgoyette-compat-0906:1.1.1.3
	netbsd-7-2-RELEASE:1.1.1.1
	pgoyette-compat-0728:1.1.1.3
	clang-337282:1.1.1.3
	netbsd-8-0-RELEASE:1.1.1.3
	phil-wifi:1.1.1.3.0.14
	phil-wifi-base:1.1.1.3
	pgoyette-compat-0625:1.1.1.3
	netbsd-8-0-RC2:1.1.1.3
	pgoyette-compat-0521:1.1.1.3
	pgoyette-compat-0502:1.1.1.3
	pgoyette-compat-0422:1.1.1.3
	netbsd-8-0-RC1:1.1.1.3
	pgoyette-compat-0415:1.1.1.3
	pgoyette-compat-0407:1.1.1.3
	pgoyette-compat-0330:1.1.1.3
	pgoyette-compat-0322:1.1.1.3
	pgoyette-compat-0315:1.1.1.3
	netbsd-7-1-2-RELEASE:1.1.1.1
	pgoyette-compat:1.1.1.3.0.12
	pgoyette-compat-base:1.1.1.3
	netbsd-7-1-1-RELEASE:1.1.1.1
	clang-319952:1.1.1.3
	matt-nb8-mediatek:1.1.1.3.0.10
	matt-nb8-mediatek-base:1.1.1.3
	clang-309604:1.1.1.3
	perseant-stdc-iso10646:1.1.1.3.0.8
	perseant-stdc-iso10646-base:1.1.1.3
	netbsd-8:1.1.1.3.0.6
	netbsd-8-base:1.1.1.3
	prg-localcount2-base3:1.1.1.3
	prg-localcount2-base2:1.1.1.3
	prg-localcount2-base1:1.1.1.3
	prg-localcount2:1.1.1.3.0.4
	prg-localcount2-base:1.1.1.3
	pgoyette-localcount-20170426:1.1.1.3
	bouyer-socketcan-base1:1.1.1.3
	pgoyette-localcount-20170320:1.1.1.3
	netbsd-7-1:1.1.1.1.0.14
	netbsd-7-1-RELEASE:1.1.1.1
	netbsd-7-1-RC2:1.1.1.1
	clang-294123:1.1.1.3
	netbsd-7-nhusb-base-20170116:1.1.1.1
	bouyer-socketcan:1.1.1.3.0.2
	bouyer-socketcan-base:1.1.1.3
	clang-291444:1.1.1.3
	pgoyette-localcount-20170107:1.1.1.2
	netbsd-7-1-RC1:1.1.1.1
	pgoyette-localcount-20161104:1.1.1.2
	netbsd-7-0-2-RELEASE:1.1.1.1
	localcount-20160914:1.1.1.2
	netbsd-7-nhusb:1.1.1.1.0.12
	netbsd-7-nhusb-base:1.1.1.1
	clang-280599:1.1.1.2
	pgoyette-localcount-20160806:1.1.1.2
	pgoyette-localcount-20160726:1.1.1.2
	pgoyette-localcount:1.1.1.2.0.2
	pgoyette-localcount-base:1.1.1.2
	netbsd-7-0-1-RELEASE:1.1.1.1
	clang-261930:1.1.1.2
	netbsd-7-0:1.1.1.1.0.10
	netbsd-7-0-RELEASE:1.1.1.1
	netbsd-7-0-RC3:1.1.1.1
	netbsd-7-0-RC2:1.1.1.1
	netbsd-7-0-RC1:1.1.1.1
	clang-237755:1.1.1.1
	clang-232565:1.1.1.1
	clang-227398:1.1.1.1
	tls-maxphys-base:1.1.1.1
	tls-maxphys:1.1.1.1.0.8
	netbsd-7:1.1.1.1.0.6
	netbsd-7-base:1.1.1.1
	clang-215315:1.1.1.1
	clang-209886:1.1.1.1
	yamt-pagecache:1.1.1.1.0.4
	yamt-pagecache-base9:1.1.1.1
	tls-earlyentropy:1.1.1.1.0.2
	tls-earlyentropy-base:1.1.1.1
	riastradh-xf86-video-intel-2-7-1-pre-2-21-15:1.1.1.1
	riastradh-drm2-base3:1.1.1.1
	clang-202566:1.1.1.1
	clang-201163:1.1.1.1
	clang-199312:1.1.1.1
	clang-198450:1.1.1.1
	clang-196603:1.1.1.1
	clang-195771:1.1.1.1
	LLVM:1.1.1;
locks; strict;
comment	@// @;


1.1
date	2013.11.28.14.14.55;	author joerg;	state Exp;
branches
	1.1.1.1;
next	;
commitid	ow8OybrawrB1f3fx;

1.1.1.1
date	2013.11.28.14.14.55;	author joerg;	state Exp;
branches
	1.1.1.1.4.1
	1.1.1.1.8.1;
next	1.1.1.2;
commitid	ow8OybrawrB1f3fx;

1.1.1.2
date	2016.02.27.22.09.11;	author joerg;	state Exp;
branches
	1.1.1.2.2.1;
next	1.1.1.3;
commitid	tIimz3oDlh1NpBWy;

1.1.1.3
date	2017.01.11.10.37.40;	author joerg;	state Exp;
branches
	1.1.1.3.14.1;
next	1.1.1.4;
commitid	CNnUNfII1jgNmxBz;

1.1.1.4
date	2019.11.13.22.19.46;	author joerg;	state dead;
branches;
next	;
commitid	QD8YATxuNG34YJKB;

1.1.1.1.4.1
date	2013.11.28.14.14.55;	author yamt;	state dead;
branches;
next	1.1.1.1.4.2;
commitid	WSrDtL5nYAUyiyBx;

1.1.1.1.4.2
date	2014.05.22.16.18.39;	author yamt;	state Exp;
branches;
next	;
commitid	WSrDtL5nYAUyiyBx;

1.1.1.1.8.1
date	2013.11.28.14.14.55;	author tls;	state dead;
branches;
next	1.1.1.1.8.2;
commitid	jTnpym9Qu0o4R1Nx;

1.1.1.1.8.2
date	2014.08.19.23.47.39;	author tls;	state Exp;
branches;
next	;
commitid	jTnpym9Qu0o4R1Nx;

1.1.1.2.2.1
date	2017.03.20.06.52.50;	author pgoyette;	state Exp;
branches;
next	;
commitid	jjw7cAwgyKq7RfKz;

1.1.1.3.14.1
date	2020.04.13.07.46.59;	author martin;	state dead;
branches;
next	;
commitid	X01YhRUPVUDaec4C;


desc
@@


1.1
log
@Initial revision
@
text
@// RUN: %clang_cc1 -fsyntax-only -verify %s

// C++'0x [class.friend] p1:
//   A friend of a class is a function or class that is given permission to use
//   the private and protected member names from the class. A class specifies
//   its friends, if any, by way of friend declarations. Such declarations give
//   special access rights to the friends, but they do not make the nominated
//   friends members of the befriending class.

struct S { static void f(); }; // expected-note 2 {{'S' declared here}}
S* g() { return 0; } // expected-note 2 {{'g' declared here}}

struct X {
  friend struct S;
  friend S* g();
};

void test1() {
  S s;
  g()->f();
  S::f();
  X::g(); // expected-error{{no member named 'g' in 'X'; did you mean simply 'g'?}}
  X::S x_s; // expected-error{{no type named 'S' in 'X'; did you mean simply 'S'?}}
  X x;
  x.g(); // expected-error{{no member named 'g' in 'X'}}
}

// Test that we recurse through namespaces to find already declared names, but
// new names are declared within the enclosing namespace.
namespace N {
  struct X {
    friend struct S;
    friend S* g();

    friend struct S2;
    friend struct S2* g2();
  };

  struct S2 { static void f2(); }; // expected-note 2 {{'S2' declared here}}
  S2* g2() { return 0; } // expected-note 2 {{'g2' declared here}}

  void test() {
    g()->f();
    S s;
    S::f();
    X::g(); // expected-error{{no member named 'g' in 'N::X'; did you mean simply 'g'?}}
    X::S x_s; // expected-error{{no type named 'S' in 'N::X'; did you mean simply 'S'?}}
    X x;
    x.g(); // expected-error{{no member named 'g' in 'N::X'}}

    g2();
    S2 s2;
    ::g2(); // expected-error{{no member named 'g2' in the global namespace; did you mean simply 'g2'?}}
    ::S2 g_s2; // expected-error{{no type named 'S2' in the global namespace; did you mean simply 'S2'?}}
    X::g2(); // expected-error{{no member named 'g2' in 'N::X'; did you mean simply 'g2'?}}
    X::S2 x_s2; // expected-error{{no type named 'S2' in 'N::X'; did you mean simply 'S2'?}}
    x.g2(); // expected-error{{no member named 'g2' in 'N::X'}}
  }
}

namespace test0 {
  class ClassFriend {
    void test();
  };

  class MemberFriend {
  public:
    void test();
  };

  void declared_test();

  class Class {
    static void member(); // expected-note 2 {{declared private here}}

    friend class ClassFriend;
    friend class UndeclaredClassFriend;

    friend void undeclared_test();
    friend void declared_test();
    friend void MemberFriend::test();
  };

  void declared_test() {
    Class::member();
  }

  void undeclared_test() {
    Class::member();
  }

  void unfriended_test() {
    Class::member(); // expected-error {{'member' is a private member of 'test0::Class'}}
  }

  void ClassFriend::test() {
    Class::member();
  }

  void MemberFriend::test() {
    Class::member();
  }

  class UndeclaredClassFriend {
    void test() {
      Class::member();
    }
  };

  class ClassNonFriend {
    void test() {
      Class::member(); // expected-error {{'member' is a private member of 'test0::Class'}}
    }
  };
}

// Make sure that friends have access to inherited protected members.
namespace test2 {
  struct X;

  class ilist_half_node {
    friend struct ilist_walker_bad;
    X *Prev;
  protected:
    X *getPrev() { return Prev; } // expected-note{{member is declared here}}
  };

  class ilist_node : private ilist_half_node { // expected-note {{declared private here}} expected-note {{constrained by private inheritance here}}
    friend struct ilist_walker;
    X *Next;
    X *getNext() { return Next; } // expected-note {{declared private here}}
  };

  struct X : ilist_node {};

  struct ilist_walker {
    static X *getPrev(X *N) { return N->getPrev(); }
    static X *getNext(X *N) { return N->getNext(); }
  };  

  struct ilist_walker_bad {
    static X *getPrev(X *N) { return N->getPrev(); } // \
    // expected-error {{'getPrev' is a private member of 'test2::ilist_half_node'}} \
    // expected-error {{cannot cast 'test2::X' to its private base class 'test2::ilist_half_node'}}

    static X *getNext(X *N) { return N->getNext(); } // \
    // expected-error {{'getNext' is a private member of 'test2::ilist_node'}}
  };  
}

namespace test3 {
  class A { protected: int x; }; // expected-note {{declared protected here}}

  class B : public A {
    friend int foo(B*);
  };

  int foo(B *p) {
    return p->x;
  }

  int foo(const B *p) {
    return p->x; // expected-error {{'x' is a protected member of 'test3::A'}}
  }
}

namespace test3a {
  class A { protected: int x; };

  class B : public A {
    friend int foo(B*);
  };

  int foo(B * const p) {
    return p->x;
  }
}

namespace test4 {
  template <class T> class Holder {
    T object;
    friend bool operator==(Holder &a, Holder &b) {
      return a.object == b.object; // expected-error {{invalid operands to binary expression}}
    }
  };

  struct Inequal {};
  bool test() {
    Holder<Inequal> a, b;
    return a == b;  // expected-note {{requested here}}
  }
}


// PR6174
namespace test5 {
  namespace ns {
    class A;
  }

  class ns::A {
  private: int x;
    friend class B;
  };

  namespace ns {
    class B {
      int test(A *p) { return p->x; }
    };
  }
}

// PR6207
namespace test6 {
  struct A {};

  struct B {
    friend A::A();
    friend A::~A();
    friend A &A::operator=(const A&);
  };
}

namespace test7 {
  template <class T> struct X {
    X();
    ~X();
    void foo();
    void bar();
  };

  class A {
    friend void X<int>::foo();
    friend X<int>::X();
    friend X<int>::X(const X&);

  private:
    A(); // expected-note 2 {{declared private here}}
  };

  template<> void X<int>::foo() {
    A a;
  }

  template<> void X<int>::bar() {
    A a; // expected-error {{calling a private constructor}}
  }

  template<> X<int>::X() {
    A a;
  }

  template<> X<int>::~X() {
    A a; // expected-error {{calling a private constructor}}
  }
}

// Return types, parameters and default arguments to friend functions.
namespace test8 {
  class A {
    typedef int I; // expected-note 4 {{declared private here}}
    static const I x = 0; // expected-note {{implicitly declared private here}}
    friend I f(I i);
    template<typename T> friend I g(I i);
  };

  const A::I A::x;
  A::I f(A::I i = A::x) {}
  template<typename T> A::I g(A::I i) {
    T t;
  }
  template A::I g<A::I>(A::I i);

  A::I f2(A::I i = A::x) {} // expected-error 3 {{is a private member of}}
  template<typename T> A::I g2(A::I i) { // expected-error 2 {{is a private member of}}
    T t;
  }
  template A::I g2<A::I>(A::I i);
}

// PR6885
namespace test9 {
  class B {
    friend class test9;
  };
}

// PR7230
namespace test10 {
  extern "C" void test10_f(void);
  extern "C" void test10_g(void);

  namespace NS {
    class C {
      void foo(void); // expected-note {{declared private here}}
      friend void test10::test10_f(void);
    };
    static C* bar;
  }

  void test10_f(void) {
    NS::bar->foo();
  }

  void test10_g(void) {
    NS::bar->foo(); // expected-error {{private member}}
  }
}

// PR8705
namespace test11 {
  class A {
  public:
    void test0(int);
    void test1(int);
    void test2(int);
    void test3(int);
  };

  class B {
    typedef int private_type; // expected-note 2 {{implicitly declared private here}}
    friend void A::test0(int);
    friend void A::test1(int);
  };

  void A::test0(B::private_type x) {}
  void A::test1(int x = B::private_type()) {}
  void A::test2(B::private_type x) {} // expected-error {{'private_type' is a private member of 'test11::B'}}
  void A::test3(int x = B::private_type()) {} // expected-error {{'private_type' is a private member of 'test11::B'}}
}


// PR9221
namespace test12 {
  struct A {
    void foo();
  };
  class B : private A {
    friend void A::foo();
    void *mem;
  };
  void A::foo() {
    void *var = static_cast<B*>(this)->mem;
  }
}

namespace PR9103 {
  struct base {
  protected:
    static void foo(void) {}
  };

  struct cls: base {
    friend void bar(void) {
      base::foo();
    }
  };
}

// PR13642.  When computing the effective context, we were walking up
// the DC chain for the canonical decl, which is unfortunate if that's
// (e.g.) a friend declaration.
namespace test14 {
  class A {
    class B { // expected-note {{implicitly declared private here}}
      static int i;
      friend void c();
    };
  };

  void c() {
    A::B::i = 5; // expected-error {{'B' is a private member of 'test14::A'}}
  }
}
@


1.1.1.1
log
@Import Clang 3.4rc1 r195771.
@
text
@@


1.1.1.2
log
@Import Clang 3.8.0rc3 r261930.
@
text
@d11 1
a11 1
S* g() { return 0; }
d15 1
a15 2
  friend S* g(); // expected-note 2 {{'g' declared here}}
  // FIXME: The above two notes would be better attached to line 11.
@


1.1.1.2.2.1
log
@Sync with HEAD
@
text
@a0 3
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++14 %s
d219 1
a219 5
    friend
#if __cplusplus >= 201103L
      constexpr
#endif
      A::A();
d221 1
a221 5
    friend
#if __cplusplus >= 201402L
      constexpr
#endif
      A &A::operator=(const A&);
d236 1
a236 5
    friend
#if __cplusplus >= 201103L
      constexpr
#endif
      X<int>::X(const X&);
@


1.1.1.3
log
@Import Clang pre-4.0.0 r291444.
@
text
@a0 3
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++14 %s
d219 1
a219 5
    friend
#if __cplusplus >= 201103L
      constexpr
#endif
      A::A();
d221 1
a221 5
    friend
#if __cplusplus >= 201402L
      constexpr
#endif
      A &A::operator=(const A&);
d236 1
a236 5
    friend
#if __cplusplus >= 201103L
      constexpr
#endif
      X<int>::X(const X&);
@


1.1.1.3.14.1
log
@Mostly merge changes from HEAD upto 20200411
@
text
@@


1.1.1.4
log
@Mark old LLVM instance as dead.
@
text
@@


1.1.1.1.8.1
log
@file p1.cpp was added on branch tls-maxphys on 2014-08-19 23:47:39 +0000
@
text
@d1 374
@


1.1.1.1.8.2
log
@Rebase to HEAD as of a few days ago.
@
text
@a0 374
// RUN: %clang_cc1 -fsyntax-only -verify %s

// C++'0x [class.friend] p1:
//   A friend of a class is a function or class that is given permission to use
//   the private and protected member names from the class. A class specifies
//   its friends, if any, by way of friend declarations. Such declarations give
//   special access rights to the friends, but they do not make the nominated
//   friends members of the befriending class.

struct S { static void f(); }; // expected-note 2 {{'S' declared here}}
S* g() { return 0; } // expected-note 2 {{'g' declared here}}

struct X {
  friend struct S;
  friend S* g();
};

void test1() {
  S s;
  g()->f();
  S::f();
  X::g(); // expected-error{{no member named 'g' in 'X'; did you mean simply 'g'?}}
  X::S x_s; // expected-error{{no type named 'S' in 'X'; did you mean simply 'S'?}}
  X x;
  x.g(); // expected-error{{no member named 'g' in 'X'}}
}

// Test that we recurse through namespaces to find already declared names, but
// new names are declared within the enclosing namespace.
namespace N {
  struct X {
    friend struct S;
    friend S* g();

    friend struct S2;
    friend struct S2* g2();
  };

  struct S2 { static void f2(); }; // expected-note 2 {{'S2' declared here}}
  S2* g2() { return 0; } // expected-note 2 {{'g2' declared here}}

  void test() {
    g()->f();
    S s;
    S::f();
    X::g(); // expected-error{{no member named 'g' in 'N::X'; did you mean simply 'g'?}}
    X::S x_s; // expected-error{{no type named 'S' in 'N::X'; did you mean simply 'S'?}}
    X x;
    x.g(); // expected-error{{no member named 'g' in 'N::X'}}

    g2();
    S2 s2;
    ::g2(); // expected-error{{no member named 'g2' in the global namespace; did you mean simply 'g2'?}}
    ::S2 g_s2; // expected-error{{no type named 'S2' in the global namespace; did you mean simply 'S2'?}}
    X::g2(); // expected-error{{no member named 'g2' in 'N::X'; did you mean simply 'g2'?}}
    X::S2 x_s2; // expected-error{{no type named 'S2' in 'N::X'; did you mean simply 'S2'?}}
    x.g2(); // expected-error{{no member named 'g2' in 'N::X'}}
  }
}

namespace test0 {
  class ClassFriend {
    void test();
  };

  class MemberFriend {
  public:
    void test();
  };

  void declared_test();

  class Class {
    static void member(); // expected-note 2 {{declared private here}}

    friend class ClassFriend;
    friend class UndeclaredClassFriend;

    friend void undeclared_test();
    friend void declared_test();
    friend void MemberFriend::test();
  };

  void declared_test() {
    Class::member();
  }

  void undeclared_test() {
    Class::member();
  }

  void unfriended_test() {
    Class::member(); // expected-error {{'member' is a private member of 'test0::Class'}}
  }

  void ClassFriend::test() {
    Class::member();
  }

  void MemberFriend::test() {
    Class::member();
  }

  class UndeclaredClassFriend {
    void test() {
      Class::member();
    }
  };

  class ClassNonFriend {
    void test() {
      Class::member(); // expected-error {{'member' is a private member of 'test0::Class'}}
    }
  };
}

// Make sure that friends have access to inherited protected members.
namespace test2 {
  struct X;

  class ilist_half_node {
    friend struct ilist_walker_bad;
    X *Prev;
  protected:
    X *getPrev() { return Prev; } // expected-note{{member is declared here}}
  };

  class ilist_node : private ilist_half_node { // expected-note {{declared private here}} expected-note {{constrained by private inheritance here}}
    friend struct ilist_walker;
    X *Next;
    X *getNext() { return Next; } // expected-note {{declared private here}}
  };

  struct X : ilist_node {};

  struct ilist_walker {
    static X *getPrev(X *N) { return N->getPrev(); }
    static X *getNext(X *N) { return N->getNext(); }
  };  

  struct ilist_walker_bad {
    static X *getPrev(X *N) { return N->getPrev(); } // \
    // expected-error {{'getPrev' is a private member of 'test2::ilist_half_node'}} \
    // expected-error {{cannot cast 'test2::X' to its private base class 'test2::ilist_half_node'}}

    static X *getNext(X *N) { return N->getNext(); } // \
    // expected-error {{'getNext' is a private member of 'test2::ilist_node'}}
  };  
}

namespace test3 {
  class A { protected: int x; }; // expected-note {{declared protected here}}

  class B : public A {
    friend int foo(B*);
  };

  int foo(B *p) {
    return p->x;
  }

  int foo(const B *p) {
    return p->x; // expected-error {{'x' is a protected member of 'test3::A'}}
  }
}

namespace test3a {
  class A { protected: int x; };

  class B : public A {
    friend int foo(B*);
  };

  int foo(B * const p) {
    return p->x;
  }
}

namespace test4 {
  template <class T> class Holder {
    T object;
    friend bool operator==(Holder &a, Holder &b) {
      return a.object == b.object; // expected-error {{invalid operands to binary expression}}
    }
  };

  struct Inequal {};
  bool test() {
    Holder<Inequal> a, b;
    return a == b;  // expected-note {{requested here}}
  }
}


// PR6174
namespace test5 {
  namespace ns {
    class A;
  }

  class ns::A {
  private: int x;
    friend class B;
  };

  namespace ns {
    class B {
      int test(A *p) { return p->x; }
    };
  }
}

// PR6207
namespace test6 {
  struct A {};

  struct B {
    friend A::A();
    friend A::~A();
    friend A &A::operator=(const A&);
  };
}

namespace test7 {
  template <class T> struct X {
    X();
    ~X();
    void foo();
    void bar();
  };

  class A {
    friend void X<int>::foo();
    friend X<int>::X();
    friend X<int>::X(const X&);

  private:
    A(); // expected-note 2 {{declared private here}}
  };

  template<> void X<int>::foo() {
    A a;
  }

  template<> void X<int>::bar() {
    A a; // expected-error {{calling a private constructor}}
  }

  template<> X<int>::X() {
    A a;
  }

  template<> X<int>::~X() {
    A a; // expected-error {{calling a private constructor}}
  }
}

// Return types, parameters and default arguments to friend functions.
namespace test8 {
  class A {
    typedef int I; // expected-note 4 {{declared private here}}
    static const I x = 0; // expected-note {{implicitly declared private here}}
    friend I f(I i);
    template<typename T> friend I g(I i);
  };

  const A::I A::x;
  A::I f(A::I i = A::x) {}
  template<typename T> A::I g(A::I i) {
    T t;
  }
  template A::I g<A::I>(A::I i);

  A::I f2(A::I i = A::x) {} // expected-error 3 {{is a private member of}}
  template<typename T> A::I g2(A::I i) { // expected-error 2 {{is a private member of}}
    T t;
  }
  template A::I g2<A::I>(A::I i);
}

// PR6885
namespace test9 {
  class B {
    friend class test9;
  };
}

// PR7230
namespace test10 {
  extern "C" void test10_f(void);
  extern "C" void test10_g(void);

  namespace NS {
    class C {
      void foo(void); // expected-note {{declared private here}}
      friend void test10::test10_f(void);
    };
    static C* bar;
  }

  void test10_f(void) {
    NS::bar->foo();
  }

  void test10_g(void) {
    NS::bar->foo(); // expected-error {{private member}}
  }
}

// PR8705
namespace test11 {
  class A {
  public:
    void test0(int);
    void test1(int);
    void test2(int);
    void test3(int);
  };

  class B {
    typedef int private_type; // expected-note 2 {{implicitly declared private here}}
    friend void A::test0(int);
    friend void A::test1(int);
  };

  void A::test0(B::private_type x) {}
  void A::test1(int x = B::private_type()) {}
  void A::test2(B::private_type x) {} // expected-error {{'private_type' is a private member of 'test11::B'}}
  void A::test3(int x = B::private_type()) {} // expected-error {{'private_type' is a private member of 'test11::B'}}
}


// PR9221
namespace test12 {
  struct A {
    void foo();
  };
  class B : private A {
    friend void A::foo();
    void *mem;
  };
  void A::foo() {
    void *var = static_cast<B*>(this)->mem;
  }
}

namespace PR9103 {
  struct base {
  protected:
    static void foo(void) {}
  };

  struct cls: base {
    friend void bar(void) {
      base::foo();
    }
  };
}

// PR13642.  When computing the effective context, we were walking up
// the DC chain for the canonical decl, which is unfortunate if that's
// (e.g.) a friend declaration.
namespace test14 {
  class A {
    class B { // expected-note {{implicitly declared private here}}
      static int i;
      friend void c();
    };
  };

  void c() {
    A::B::i = 5; // expected-error {{'B' is a private member of 'test14::A'}}
  }
}
@


1.1.1.1.4.1
log
@file p1.cpp was added on branch yamt-pagecache on 2014-05-22 16:18:39 +0000
@
text
@d1 374
@


1.1.1.1.4.2
log
@sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs.  ("Protocol error: too many arguments")
@
text
@a0 374
// RUN: %clang_cc1 -fsyntax-only -verify %s

// C++'0x [class.friend] p1:
//   A friend of a class is a function or class that is given permission to use
//   the private and protected member names from the class. A class specifies
//   its friends, if any, by way of friend declarations. Such declarations give
//   special access rights to the friends, but they do not make the nominated
//   friends members of the befriending class.

struct S { static void f(); }; // expected-note 2 {{'S' declared here}}
S* g() { return 0; } // expected-note 2 {{'g' declared here}}

struct X {
  friend struct S;
  friend S* g();
};

void test1() {
  S s;
  g()->f();
  S::f();
  X::g(); // expected-error{{no member named 'g' in 'X'; did you mean simply 'g'?}}
  X::S x_s; // expected-error{{no type named 'S' in 'X'; did you mean simply 'S'?}}
  X x;
  x.g(); // expected-error{{no member named 'g' in 'X'}}
}

// Test that we recurse through namespaces to find already declared names, but
// new names are declared within the enclosing namespace.
namespace N {
  struct X {
    friend struct S;
    friend S* g();

    friend struct S2;
    friend struct S2* g2();
  };

  struct S2 { static void f2(); }; // expected-note 2 {{'S2' declared here}}
  S2* g2() { return 0; } // expected-note 2 {{'g2' declared here}}

  void test() {
    g()->f();
    S s;
    S::f();
    X::g(); // expected-error{{no member named 'g' in 'N::X'; did you mean simply 'g'?}}
    X::S x_s; // expected-error{{no type named 'S' in 'N::X'; did you mean simply 'S'?}}
    X x;
    x.g(); // expected-error{{no member named 'g' in 'N::X'}}

    g2();
    S2 s2;
    ::g2(); // expected-error{{no member named 'g2' in the global namespace; did you mean simply 'g2'?}}
    ::S2 g_s2; // expected-error{{no type named 'S2' in the global namespace; did you mean simply 'S2'?}}
    X::g2(); // expected-error{{no member named 'g2' in 'N::X'; did you mean simply 'g2'?}}
    X::S2 x_s2; // expected-error{{no type named 'S2' in 'N::X'; did you mean simply 'S2'?}}
    x.g2(); // expected-error{{no member named 'g2' in 'N::X'}}
  }
}

namespace test0 {
  class ClassFriend {
    void test();
  };

  class MemberFriend {
  public:
    void test();
  };

  void declared_test();

  class Class {
    static void member(); // expected-note 2 {{declared private here}}

    friend class ClassFriend;
    friend class UndeclaredClassFriend;

    friend void undeclared_test();
    friend void declared_test();
    friend void MemberFriend::test();
  };

  void declared_test() {
    Class::member();
  }

  void undeclared_test() {
    Class::member();
  }

  void unfriended_test() {
    Class::member(); // expected-error {{'member' is a private member of 'test0::Class'}}
  }

  void ClassFriend::test() {
    Class::member();
  }

  void MemberFriend::test() {
    Class::member();
  }

  class UndeclaredClassFriend {
    void test() {
      Class::member();
    }
  };

  class ClassNonFriend {
    void test() {
      Class::member(); // expected-error {{'member' is a private member of 'test0::Class'}}
    }
  };
}

// Make sure that friends have access to inherited protected members.
namespace test2 {
  struct X;

  class ilist_half_node {
    friend struct ilist_walker_bad;
    X *Prev;
  protected:
    X *getPrev() { return Prev; } // expected-note{{member is declared here}}
  };

  class ilist_node : private ilist_half_node { // expected-note {{declared private here}} expected-note {{constrained by private inheritance here}}
    friend struct ilist_walker;
    X *Next;
    X *getNext() { return Next; } // expected-note {{declared private here}}
  };

  struct X : ilist_node {};

  struct ilist_walker {
    static X *getPrev(X *N) { return N->getPrev(); }
    static X *getNext(X *N) { return N->getNext(); }
  };  

  struct ilist_walker_bad {
    static X *getPrev(X *N) { return N->getPrev(); } // \
    // expected-error {{'getPrev' is a private member of 'test2::ilist_half_node'}} \
    // expected-error {{cannot cast 'test2::X' to its private base class 'test2::ilist_half_node'}}

    static X *getNext(X *N) { return N->getNext(); } // \
    // expected-error {{'getNext' is a private member of 'test2::ilist_node'}}
  };  
}

namespace test3 {
  class A { protected: int x; }; // expected-note {{declared protected here}}

  class B : public A {
    friend int foo(B*);
  };

  int foo(B *p) {
    return p->x;
  }

  int foo(const B *p) {
    return p->x; // expected-error {{'x' is a protected member of 'test3::A'}}
  }
}

namespace test3a {
  class A { protected: int x; };

  class B : public A {
    friend int foo(B*);
  };

  int foo(B * const p) {
    return p->x;
  }
}

namespace test4 {
  template <class T> class Holder {
    T object;
    friend bool operator==(Holder &a, Holder &b) {
      return a.object == b.object; // expected-error {{invalid operands to binary expression}}
    }
  };

  struct Inequal {};
  bool test() {
    Holder<Inequal> a, b;
    return a == b;  // expected-note {{requested here}}
  }
}


// PR6174
namespace test5 {
  namespace ns {
    class A;
  }

  class ns::A {
  private: int x;
    friend class B;
  };

  namespace ns {
    class B {
      int test(A *p) { return p->x; }
    };
  }
}

// PR6207
namespace test6 {
  struct A {};

  struct B {
    friend A::A();
    friend A::~A();
    friend A &A::operator=(const A&);
  };
}

namespace test7 {
  template <class T> struct X {
    X();
    ~X();
    void foo();
    void bar();
  };

  class A {
    friend void X<int>::foo();
    friend X<int>::X();
    friend X<int>::X(const X&);

  private:
    A(); // expected-note 2 {{declared private here}}
  };

  template<> void X<int>::foo() {
    A a;
  }

  template<> void X<int>::bar() {
    A a; // expected-error {{calling a private constructor}}
  }

  template<> X<int>::X() {
    A a;
  }

  template<> X<int>::~X() {
    A a; // expected-error {{calling a private constructor}}
  }
}

// Return types, parameters and default arguments to friend functions.
namespace test8 {
  class A {
    typedef int I; // expected-note 4 {{declared private here}}
    static const I x = 0; // expected-note {{implicitly declared private here}}
    friend I f(I i);
    template<typename T> friend I g(I i);
  };

  const A::I A::x;
  A::I f(A::I i = A::x) {}
  template<typename T> A::I g(A::I i) {
    T t;
  }
  template A::I g<A::I>(A::I i);

  A::I f2(A::I i = A::x) {} // expected-error 3 {{is a private member of}}
  template<typename T> A::I g2(A::I i) { // expected-error 2 {{is a private member of}}
    T t;
  }
  template A::I g2<A::I>(A::I i);
}

// PR6885
namespace test9 {
  class B {
    friend class test9;
  };
}

// PR7230
namespace test10 {
  extern "C" void test10_f(void);
  extern "C" void test10_g(void);

  namespace NS {
    class C {
      void foo(void); // expected-note {{declared private here}}
      friend void test10::test10_f(void);
    };
    static C* bar;
  }

  void test10_f(void) {
    NS::bar->foo();
  }

  void test10_g(void) {
    NS::bar->foo(); // expected-error {{private member}}
  }
}

// PR8705
namespace test11 {
  class A {
  public:
    void test0(int);
    void test1(int);
    void test2(int);
    void test3(int);
  };

  class B {
    typedef int private_type; // expected-note 2 {{implicitly declared private here}}
    friend void A::test0(int);
    friend void A::test1(int);
  };

  void A::test0(B::private_type x) {}
  void A::test1(int x = B::private_type()) {}
  void A::test2(B::private_type x) {} // expected-error {{'private_type' is a private member of 'test11::B'}}
  void A::test3(int x = B::private_type()) {} // expected-error {{'private_type' is a private member of 'test11::B'}}
}


// PR9221
namespace test12 {
  struct A {
    void foo();
  };
  class B : private A {
    friend void A::foo();
    void *mem;
  };
  void A::foo() {
    void *var = static_cast<B*>(this)->mem;
  }
}

namespace PR9103 {
  struct base {
  protected:
    static void foo(void) {}
  };

  struct cls: base {
    friend void bar(void) {
      base::foo();
    }
  };
}

// PR13642.  When computing the effective context, we were walking up
// the DC chain for the canonical decl, which is unfortunate if that's
// (e.g.) a friend declaration.
namespace test14 {
  class A {
    class B { // expected-note {{implicitly declared private here}}
      static int i;
      friend void c();
    };
  };

  void c() {
    A::B::i = 5; // expected-error {{'B' is a private member of 'test14::A'}}
  }
}
@


