head	1.1;
branch	1.1.1;
access;
symbols
	netbsd-11-0-RC4:1.1.1.5
	netbsd-11-0-RC3:1.1.1.5
	netbsd-11-0-RC2:1.1.1.5
	netbsd-11-0-RC1:1.1.1.5
	perseant-exfatfs-base-20250801:1.1.1.5
	netbsd-11:1.1.1.5.0.10
	netbsd-11-base:1.1.1.5
	netbsd-10-1-RELEASE:1.1.1.5
	perseant-exfatfs-base-20240630:1.1.1.5
	perseant-exfatfs:1.1.1.5.0.8
	perseant-exfatfs-base:1.1.1.5
	netbsd-8-3-RELEASE:1.1.1.3
	netbsd-9-4-RELEASE:1.1.1.4
	netbsd-10-0-RELEASE:1.1.1.5
	netbsd-10-0-RC6:1.1.1.5
	netbsd-10-0-RC5:1.1.1.5
	netbsd-10-0-RC4:1.1.1.5
	netbsd-10-0-RC3:1.1.1.5
	netbsd-10-0-RC2:1.1.1.5
	netbsd-10-0-RC1:1.1.1.5
	netbsd-10:1.1.1.5.0.6
	netbsd-10-base:1.1.1.5
	netbsd-9-3-RELEASE:1.1.1.4
	cjep_sun2x:1.1.1.5.0.4
	cjep_sun2x-base:1.1.1.5
	cjep_staticlib_x-base1:1.1.1.5
	netbsd-9-2-RELEASE:1.1.1.4
	cjep_staticlib_x:1.1.1.5.0.2
	cjep_staticlib_x-base:1.1.1.5
	netbsd-9-1-RELEASE:1.1.1.4
	phil-wifi-20200421:1.1.1.5
	phil-wifi-20200411:1.1.1.5
	phil-wifi-20200406:1.1.1.5
	netbsd-8-2-RELEASE:1.1.1.3
	netbsd-9-0-RELEASE:1.1.1.4
	netbsd-9-0-RC2:1.1.1.4
	netbsd-9-0-RC1:1.1.1.4
	netbsd-9:1.1.1.4.0.6
	netbsd-9-base:1.1.1.4
	phil-wifi-20190609:1.1.1.4
	netbsd-8-1-RELEASE:1.1.1.3
	netbsd-8-1-RC1:1.1.1.3
	pgoyette-compat-merge-20190127:1.1.1.4
	pgoyette-compat-20190127:1.1.1.4
	pgoyette-compat-20190118:1.1.1.4
	pgoyette-compat-1226:1.1.1.4
	pgoyette-compat-1126:1.1.1.4
	pgoyette-compat-1020:1.1.1.4
	pgoyette-compat-0930:1.1.1.4
	pgoyette-compat-0906:1.1.1.4
	netbsd-7-2-RELEASE:1.1.1.2
	pgoyette-compat-0728:1.1.1.4
	clang-337282:1.1.1.4
	netbsd-8-0-RELEASE:1.1.1.3
	phil-wifi:1.1.1.4.0.4
	phil-wifi-base:1.1.1.4
	pgoyette-compat-0625:1.1.1.4
	netbsd-8-0-RC2:1.1.1.3
	pgoyette-compat-0521:1.1.1.4
	pgoyette-compat-0502:1.1.1.4
	pgoyette-compat-0422:1.1.1.4
	netbsd-8-0-RC1:1.1.1.3
	pgoyette-compat-0415:1.1.1.4
	pgoyette-compat-0407:1.1.1.4
	pgoyette-compat-0330:1.1.1.4
	pgoyette-compat-0322:1.1.1.4
	pgoyette-compat-0315:1.1.1.4
	netbsd-7-1-2-RELEASE:1.1.1.2
	pgoyette-compat:1.1.1.4.0.2
	pgoyette-compat-base:1.1.1.4
	netbsd-7-1-1-RELEASE:1.1.1.2
	clang-319952:1.1.1.4
	matt-nb8-mediatek:1.1.1.3.0.10
	matt-nb8-mediatek-base:1.1.1.3
	clang-309604:1.1.1.4
	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.2.0.16
	netbsd-7-1-RELEASE:1.1.1.2
	netbsd-7-1-RC2:1.1.1.2
	clang-294123:1.1.1.3
	netbsd-7-nhusb-base-20170116:1.1.1.2
	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.2
	pgoyette-localcount-20161104:1.1.1.2
	netbsd-7-0-2-RELEASE:1.1.1.2
	localcount-20160914:1.1.1.2
	netbsd-7-nhusb:1.1.1.2.0.14
	netbsd-7-nhusb-base:1.1.1.2
	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.12
	pgoyette-localcount-base:1.1.1.2
	netbsd-7-0-1-RELEASE:1.1.1.2
	clang-261930:1.1.1.2
	netbsd-7-0:1.1.1.2.0.10
	netbsd-7-0-RELEASE:1.1.1.2
	netbsd-7-0-RC3:1.1.1.2
	netbsd-7-0-RC2:1.1.1.2
	netbsd-7-0-RC1:1.1.1.2
	clang-237755:1.1.1.2
	clang-232565:1.1.1.2
	clang-227398:1.1.1.2
	tls-maxphys-base:1.1.1.2
	tls-maxphys:1.1.1.2.0.8
	netbsd-7:1.1.1.2.0.6
	netbsd-7-base:1.1.1.2
	clang-215315:1.1.1.2
	clang-209886:1.1.1.2
	yamt-pagecache:1.1.1.2.0.4
	yamt-pagecache-base9:1.1.1.2
	tls-earlyentropy:1.1.1.2.0.2
	tls-earlyentropy-base:1.1.1.2
	riastradh-xf86-video-intel-2-7-1-pre-2-21-15:1.1.1.2
	riastradh-drm2-base3:1.1.1.2
	clang-202566:1.1.1.2
	clang-201163:1.1.1.2
	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;
next	1.1.1.2;
commitid	ow8OybrawrB1f3fx;

1.1.1.2
date	2014.02.14.20.07.36;	author joerg;	state Exp;
branches
	1.1.1.2.4.1
	1.1.1.2.8.1
	1.1.1.2.12.1;
next	1.1.1.3;
commitid	annVkZ1sc17rF6px;

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

1.1.1.4
date	2017.08.01.19.34.29;	author joerg;	state Exp;
branches
	1.1.1.4.4.1;
next	1.1.1.5;
commitid	pMuDy65V0VicSx1A;

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

1.1.1.2.4.1
date	2014.02.14.20.07.36;	author yamt;	state dead;
branches;
next	1.1.1.2.4.2;
commitid	WSrDtL5nYAUyiyBx;

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

1.1.1.2.8.1
date	2014.02.14.20.07.36;	author tls;	state dead;
branches;
next	1.1.1.2.8.2;
commitid	jTnpym9Qu0o4R1Nx;

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

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

1.1.1.4.4.1
date	2020.04.13.07.46.58;	author martin;	state dead;
branches;
next	;
commitid	X01YhRUPVUDaec4C;


desc
@@


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

// C++0x [class.access]p4:

//   Access control is applied uniformly to all names, whether the
//   names are referred to from declarations or expressions.  In the
//   case of overloaded function names, access control is applied to
//   the function selected by overload resolution.

class Public {} PublicInst;
class Protected {} ProtectedInst;
class Private {} PrivateInst;

namespace test0 {
  class A {
  public:
    void foo(Public&);
  protected:
    void foo(Protected&); // expected-note 2 {{declared protected here}}
  private:
    void foo(Private&); // expected-note 2 {{declared private here}}
  };

  void test(A *op) {
    op->foo(PublicInst);
    op->foo(ProtectedInst); // expected-error {{'foo' is a protected member}}
    op->foo(PrivateInst); // expected-error {{'foo' is a private member}}

    void (A::*a)(Public&) = &A::foo;
    void (A::*b)(Protected&) = &A::foo; // expected-error {{'foo' is a protected member}}
    void (A::*c)(Private&) = &A::foo; // expected-error {{'foo' is a private member}}
  }
}

// Member operators.
namespace test1 {
  class A {
  public:
    void operator+(Public&);
    void operator[](Public&);
    void operator()(Public&);
    typedef void (*PublicSurrogate)(Public&);
    operator PublicSurrogate() const;
  protected:
    void operator+(Protected&); // expected-note {{declared protected here}}
    void operator[](Protected&); // expected-note {{declared protected here}}
    void operator()(Protected&); // expected-note {{declared protected here}}
    typedef void (*ProtectedSurrogate)(Protected&);
    operator ProtectedSurrogate() const; // expected-note {{declared protected here}}
  private:
    void operator+(Private&); // expected-note {{declared private here}}
    void operator[](Private&); // expected-note {{declared private here}}
    void operator()(Private&); // expected-note {{declared private here}}
    void operator-(); // expected-note {{declared private here}}
    typedef void (*PrivateSurrogate)(Private&);
    operator PrivateSurrogate() const; // expected-note {{declared private here}}
  };
  void operator+(const A &, Public&);
  void operator+(const A &, Protected&);
  void operator+(const A &, Private&);
  void operator-(const A &);

  void test(A &a, Public &pub, Protected &prot, Private &priv) {
    a + pub;
    a + prot; // expected-error {{'operator+' is a protected member}}
    a + priv; // expected-error {{'operator+' is a private member}}
    a[pub];
    a[prot]; // expected-error {{'operator[]' is a protected member}}
    a[priv]; // expected-error {{'operator[]' is a private member}}
    a(pub);
    a(prot); // expected-error {{'operator()' is a protected member}}
    a(priv); // expected-error {{'operator()' is a private member}}
    -a;       // expected-error {{'operator-' is a private member}}

    const A &ca = a;
    ca + pub;
    ca + prot;
    ca + priv;
    -ca;
    // These are all surrogate calls
    ca(pub);
    ca(prot); // expected-error {{'operator void (*)(class Protected &)' is a protected member}}
    ca(priv); // expected-error {{'operator void (*)(class Private &)' is a private member}}
  }
}

// Implicit constructor calls.
namespace test2 {
  class A {
  private:
    A(); // expected-note 3 {{declared private here}}

    static A foo;
  };

  A a; // expected-error {{calling a private constructor}}
  A A::foo; // okay
  
  class B : A { }; // expected-error {{base class 'test2::A' has private default constructor}}
  B b; // expected-note{{implicit default constructor}}
  
  class C : virtual A { 
  public:
    C();
  };

  class D : C { }; // expected-error {{inherited virtual base class 'test2::A' has private default constructor}}
  D d; // expected-note{{implicit default constructor}}
}

// Implicit destructor calls.
namespace test3 {
  class A {
  private:
    ~A(); // expected-note 2 {{declared private here}}
    static A foo;
  };

  A a; // expected-error {{variable of type 'test3::A' has private destructor}}
  A A::foo;

  void foo(A param) { // okay
    A local; // expected-error {{variable of type 'test3::A' has private destructor}}
  }

  template <unsigned N> class Base { ~Base(); }; // expected-note 14 {{declared private here}}
  class Base2 : virtual Base<2> { ~Base2(); }; // expected-note 3 {{declared private here}} \
                                               // expected-error {{base class 'Base<2>' has private destructor}}
  class Base3 : virtual Base<3> { public: ~Base3(); }; // expected-error {{base class 'Base<3>' has private destructor}}

  // These don't cause diagnostics because we don't need the destructor.
  class Derived0 : Base<0> { ~Derived0(); };
  class Derived1 : Base<1> { };

  class Derived2 : // expected-error {{inherited virtual base class 'Base<2>' has private destructor}} \
                   // expected-error {{inherited virtual base class 'Base<3>' has private destructor}}
    Base<0>,  // expected-error {{base class 'Base<0>' has private destructor}}
    virtual Base<1>, // expected-error {{base class 'Base<1>' has private destructor}}
    Base2, // expected-error {{base class 'test3::Base2' has private destructor}}
    virtual Base3
  {
    ~Derived2() {}
  };

  class Derived3 : // expected-error 2 {{inherited virtual base class 'Base<2>' has private destructor}} \
                   // expected-error 2 {{inherited virtual base class 'Base<3>' has private destructor}} \
    // expected-note 2{{implicit default constructor}}
    Base<0>,  // expected-error 2 {{base class 'Base<0>' has private destructor}}
    virtual Base<1>, // expected-error 2 {{base class 'Base<1>' has private destructor}}
    Base2, // expected-error 2 {{base class 'test3::Base2' has private destructor}}
    virtual Base3
  {}; 
  Derived3 d3; // expected-note {{implicit default constructor}}\
               // expected-note{{implicit destructor}}}
}

// Conversion functions.
namespace test4 {
  class Base {
  private:
    operator Private(); // expected-note 4 {{declared private here}}
  public:
    operator Public(); // expected-note 2{{member is declared here}}
  };

  class Derived1 : private Base { // expected-note 2 {{declared private here}} \
                                  // expected-note {{constrained by private inheritance}}
    Private test1() { return *this; } // expected-error {{'operator Private' is a private member}}
    Public test2() { return *this; }
  };
  Private test1(Derived1 &d) { return d; } // expected-error {{'operator Private' is a private member}} \
                                           // expected-error {{cannot cast 'test4::Derived1' to its private base class}}
  Public test2(Derived1 &d) { return d; } // expected-error {{cannot cast 'test4::Derived1' to its private base class}} \
                                          // expected-error {{'operator Public' is a private member}}


  class Derived2 : public Base {
    Private test1() { return *this; } // expected-error {{'operator Private' is a private member}}
    Public test2() { return *this; }
  };
  Private test1(Derived2 &d) { return d; } // expected-error {{'operator Private' is a private member}}
  Public test2(Derived2 &d) { return d; }

  class Derived3 : private Base { // expected-note {{constrained by private inheritance here}} \
                                  // expected-note {{declared private here}}
  public:
    operator Private();
  };
  Private test1(Derived3 &d) { return d; }
  Public test2(Derived3 &d) { return d; } // expected-error {{'operator Public' is a private member of 'test4::Base'}} \
                                          // expected-error {{cannot cast 'test4::Derived3' to its private base class}}

  class Derived4 : public Base {
  public:
    operator Private();
  };
  Private test1(Derived4 &d) { return d; }
  Public test2(Derived4 &d) { return d; }
}

// Implicit copy assignment operator uses.
namespace test5 {
  class A {
    void operator=(const A &); // expected-note 2 {{implicitly declared private here}}
  };

  class Test1 { A a; }; // expected-error {{private member}}
  void test1() {
    Test1 a; 
    a = Test1(); // expected-note{{implicit copy}}
  }

  class Test2 : A {}; // expected-error {{private member}}
  void test2() {
    Test2 a;
    a = Test2(); // expected-note{{implicit copy}}
  }
}

// Implicit copy constructor uses.
namespace test6 {
  class A {
    public: A();
    private: A(const A &); // expected-note 2 {{declared private here}}
  };

  class Test1 { A a; }; // expected-error {{field of type 'test6::A' has private copy constructor}}
  void test1(const Test1 &t) {
    Test1 a = t; // expected-note{{implicit copy}}
  }

  class Test2 : A {}; // expected-error {{base class 'test6::A' has private copy constructor}}
  void test2(const Test2 &t) {
    Test2 a = t; // expected-note{{implicit copy}}
  }
}

// Redeclaration lookups are not accesses.
namespace test7 {
  class A {
    int private_member;
  };
  class B : A {
    int foo(int private_member) {
      return 0;
    }
  };
}

// Ignored operator new and delete overloads are not 
namespace test8 {
  typedef __typeof__(sizeof(int)) size_t;

  class A {
    void *operator new(size_t s);
    void operator delete(void *p);
  public:
    void *operator new(size_t s, int n);
    void operator delete(void *p, int n);
  };

  void test() {
    new (2) A();
  }
}

// Don't silently upgrade forbidden-access paths to private.
namespace test9 {
  class A {
  public: static int x; // expected-note {{member is declared here}}
  };
  class B : private A { // expected-note {{constrained by private inheritance here}}
  };
  class C : public B {
    static int getX() { return x; } // expected-error {{'x' is a private member of 'test9::A'}}
  };
}

namespace test10 {
  class A {
    enum {
      value = 10 // expected-note {{declared private here}}
    };
    friend class C;
  };

  class B {
    enum {
      value = A::value // expected-error {{'value' is a private member of 'test10::A'}}
    };
  };

  class C {
    enum {
      value = A::value
    };
  };
}

namespace test11 {
  class A {
    protected: virtual ~A();
  };

  class B : public A {
    ~B();
  };

  B::~B() {};
}

namespace test12 {
  class A {
    int x;

    void foo() {
      class Local {
        int foo(A *a) {
          return a->x;
        }
      };
    }
  };
}

namespace test13 {
  struct A {
    int x;
    unsigned foo() const;
  };

  struct B : protected A {
    using A::foo;
    using A::x;
  };

  void test() {
    A *d;
    d->foo();
    (void) d->x;
  }
}

// Destructors for temporaries.
namespace test14 {
  class A {
  private: ~A(); // expected-note {{declared private here}}
  };
  A foo();

  void test() {
    foo(); // expected-error {{temporary of type 'test14::A' has private destructor}}
  }

  class X {
    ~X(); // expected-note {{declared private here}}
  };
  
  struct Y1 {
    operator X();
  };
  
  void g() {
    const X &xr = Y1(); // expected-error{{temporary of type 'test14::X' has private destructor}}
  }
}

// PR 7024
namespace test15 {
  template <class T> class A {
  private:
    int private_foo; // expected-note {{declared private here}}
    static int private_sfoo; // expected-note {{declared private here}}
  protected:
    int protected_foo; // expected-note 3 {{declared protected here}} // expected-note {{can only access this member on an object of type 'test15::B<int>'}}
    static int protected_sfoo; // expected-note 3 {{declared protected here}}

    int test1(A<int> &a) {
      return a.private_foo; // expected-error {{private member}}
    }

    int test2(A<int> &a) {
      return a.private_sfoo; // expected-error {{private member}}
    }

    int test3(A<int> &a) {
      return a.protected_foo; // expected-error {{protected member}}
    }

    int test4(A<int> &a) {
      return a.protected_sfoo; // expected-error {{protected member}}
    }
  };

  template class A<int>;
  template class A<long>; // expected-note 4 {{in instantiation}} 

  template <class T> class B : public A<T> {
    // TODO: These first two accesses can be detected as ill-formed at
    // definition time because they're member accesses and A<int> can't
    // be a subclass of B<T> for any T.

    int test1(A<int> &a) {
      return a.protected_foo; // expected-error 2 {{protected member}}
    }

    int test2(A<int> &a) {
      return a.protected_sfoo; // expected-error {{protected member}}
    }

    int test3(B<int> &b) {
      return b.protected_foo; // expected-error {{protected member}}
    }

    int test4(B<int> &b) {
      return b.protected_sfoo; // expected-error {{protected member}}
    }
  };

  template class B<int>;  // expected-note {{in instantiation}}
  template class B<long>; // expected-note 4 {{in instantiation}}
}

// PR7281
namespace test16 {
  class A { ~A(); }; // expected-note 2{{declared private here}}
  void b() { throw A(); } // expected-error{{temporary of type 'test16::A' has private destructor}} \
  // expected-error{{exception object of type 'test16::A' has private destructor}}
}

// rdar://problem/8146294
namespace test17 {
  class A {
    template <typename T> class Inner { }; // expected-note {{declared private here}}
  };

  A::Inner<int> s; // expected-error {{'Inner' is a private member of 'test17::A'}}
}

namespace test18 {
  template <class T> class A {};
  class B : A<int> {
    A<int> member;
  };

  // FIXME: this access to A should be forbidden (because C++ is dumb),
  // but LookupResult can't express the necessary information to do
  // the check, so we aggressively suppress access control.
  class C : B {
    A<int> member;
  };
}

// PR8325
namespace test19 {
  class A { ~A(); };
  // The destructor is not implicitly referenced here.  Contrast to test16, 
  // testing PR7281, earlier in this file.
  void b(A* x) { throw x; }
}

// PR7930
namespace test20 {
  class Foo {
    Foo(); // expected-note {{implicitly declared private here}}
  };
  Foo::Foo() {}

  void test() {
    Foo a; // expected-error {{calling a private constructor}}
  }
}

namespace test21 {
  template <class T> class A {
    void foo();
    void bar();
    class Inner; // expected-note {{implicitly declared private here}}
  public:
    void baz();
  };
  template <class T> class A<T>::Inner {};
  class B {
    template <class T> class A<T>::Inner; // expected-error{{non-friend class member 'Inner' cannot have a qualified name}}
  };

  void test() {
    A<int>::Inner i; // expected-error {{'Inner' is a private member}}
  }
}

namespace rdar8876150 {
  struct A { operator bool(); };
  struct B : private A { using A::operator bool; };

  bool f() {
    B b;
    return !b;
  }
}

namespace test23 {
  template <typename T> class A {
    A();
    static A instance;
  };

  template <typename T> A<T> A<T>::instance;
  template class A<int>;
}
@


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


1.1.1.2
log
@Import Clang 3.5svn r201163.
@
text
@d82 2
a83 2
    ca(prot); // expected-error {{'operator void (*)(Protected &)' is a protected member}}
    ca(priv); // expected-error {{'operator void (*)(Private &)' is a private member}}
@


1.1.1.2.12.1
log
@Sync with HEAD
@
text
@a0 2
// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -fsyntax-only -verify -std=c++98 %s
// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -fsyntax-only -verify -std=c++11 %s
d91 1
a91 1
    A(); // expected-note 1+{{declared private here}}
a98 1
#if __cplusplus < 201103L
a108 13
#else
  class B : A { }; // expected-note {{base class 'test2::A' has an inaccessible default constructor}}
  B b; // expected-error {{call to implicitly-deleted default constructor}}
  
  // FIXME: Do a better job of explaining how we get here from class D.
  class C : virtual A { // expected-note {{default constructor of 'D' is implicitly deleted because base class 'test2::A' has an inaccessible default constructor}}
  public:
    C();
  };

  class D : C { };
  D d; // expected-error {{call to implicitly-deleted default constructor}}
#endif
a125 1
#if __cplusplus < 201103L
a154 27
#else
  template <unsigned N> class Base { ~Base(); }; // expected-note 4{{declared private here}}
  class Base2 : virtual Base<2> { ~Base2(); }; // expected-note 1{{declared private here}}
  class Base3 : virtual Base<3> { public: ~Base3(); };

  // These don't cause diagnostics because we don't need the destructor.
  class Derived0 : Base<0> { ~Derived0(); };
  class Derived1 : Base<1> { };

  class Derived2 : // expected-error {{inherited virtual base class 'Base<2>' has private destructor}} \
                   // expected-error {{inherited virtual base class 'Base<3>' has private destructor}}
    Base<0>,  // expected-error {{base class 'Base<0>' has private destructor}}
    virtual Base<1>, // expected-error {{base class 'Base<1>' has private destructor}}
    Base2, // expected-error {{base class 'test3::Base2' has private destructor}}
    virtual Base3
  {
    ~Derived2() {}
  };

  class Derived3 :
    Base<0>, // expected-note {{deleted because base class 'Base<0>' has an inaccessible destructor}}
    virtual Base<1>,
    Base2,
    virtual Base3
  {}; 
  Derived3 d3; // expected-error {{implicitly-deleted default constructor}}
#endif
d204 1
a204 4
    void operator=(const A &);
#if __cplusplus < 201103L
    // expected-note@@-2 2{{implicitly declared private here}}
#endif
a206 1
#if __cplusplus < 201103L
a217 13
#else
  class Test1 { A a; }; // expected-note {{because field 'a' has an inaccessible copy assignment operator}}
  void test1() {
    Test1 a; 
    a = Test1(); // expected-error {{copy assignment operator is implicitly deleted}}
  }

  class Test2 : A {}; // expected-note {{because base class 'test5::A' has an inaccessible copy assignment operator}}
  void test2() {
    Test2 a;
    a = Test2(); // expected-error {{copy assignment operator is implicitly deleted}}
  }
#endif
d224 1
a224 4
    private: A(const A &);
#if __cplusplus < 201103L
    // expected-note@@-2 2{{declared private here}}
#endif
a226 1
#if __cplusplus < 201103L
a235 11
#else
  class Test1 { A a; }; // expected-note {{field 'a' has an inaccessible copy constructor}}
  void test1(const Test1 &t) {
    Test1 a = t; // expected-error{{implicitly-deleted}}
  }

  class Test2 : A {}; // expected-note {{base class 'test6::A' has an inaccessible copy constructor}}
  void test2(const Test2 &t) {
    Test2 a = t; // expected-error{{implicitly-deleted}}
  }
#endif
@


1.1.1.3
log
@Import Clang pre-4.0.0 r291444.
@
text
@a0 2
// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -fsyntax-only -verify -std=c++98 %s
// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -fsyntax-only -verify -std=c++11 %s
d91 1
a91 1
    A(); // expected-note 1+{{declared private here}}
a98 1
#if __cplusplus < 201103L
a108 13
#else
  class B : A { }; // expected-note {{base class 'test2::A' has an inaccessible default constructor}}
  B b; // expected-error {{call to implicitly-deleted default constructor}}
  
  // FIXME: Do a better job of explaining how we get here from class D.
  class C : virtual A { // expected-note {{default constructor of 'D' is implicitly deleted because base class 'test2::A' has an inaccessible default constructor}}
  public:
    C();
  };

  class D : C { };
  D d; // expected-error {{call to implicitly-deleted default constructor}}
#endif
a125 1
#if __cplusplus < 201103L
a154 27
#else
  template <unsigned N> class Base { ~Base(); }; // expected-note 4{{declared private here}}
  class Base2 : virtual Base<2> { ~Base2(); }; // expected-note 1{{declared private here}}
  class Base3 : virtual Base<3> { public: ~Base3(); };

  // These don't cause diagnostics because we don't need the destructor.
  class Derived0 : Base<0> { ~Derived0(); };
  class Derived1 : Base<1> { };

  class Derived2 : // expected-error {{inherited virtual base class 'Base<2>' has private destructor}} \
                   // expected-error {{inherited virtual base class 'Base<3>' has private destructor}}
    Base<0>,  // expected-error {{base class 'Base<0>' has private destructor}}
    virtual Base<1>, // expected-error {{base class 'Base<1>' has private destructor}}
    Base2, // expected-error {{base class 'test3::Base2' has private destructor}}
    virtual Base3
  {
    ~Derived2() {}
  };

  class Derived3 :
    Base<0>, // expected-note {{deleted because base class 'Base<0>' has an inaccessible destructor}}
    virtual Base<1>,
    Base2,
    virtual Base3
  {}; 
  Derived3 d3; // expected-error {{implicitly-deleted default constructor}}
#endif
d204 1
a204 4
    void operator=(const A &);
#if __cplusplus < 201103L
    // expected-note@@-2 2{{implicitly declared private here}}
#endif
a206 1
#if __cplusplus < 201103L
a217 13
#else
  class Test1 { A a; }; // expected-note {{because field 'a' has an inaccessible copy assignment operator}}
  void test1() {
    Test1 a; 
    a = Test1(); // expected-error {{copy assignment operator is implicitly deleted}}
  }

  class Test2 : A {}; // expected-note {{because base class 'test5::A' has an inaccessible copy assignment operator}}
  void test2() {
    Test2 a;
    a = Test2(); // expected-error {{copy assignment operator is implicitly deleted}}
  }
#endif
d224 1
a224 4
    private: A(const A &);
#if __cplusplus < 201103L
    // expected-note@@-2 2{{declared private here}}
#endif
a226 1
#if __cplusplus < 201103L
a235 11
#else
  class Test1 { A a; }; // expected-note {{field 'a' has an inaccessible copy constructor}}
  void test1(const Test1 &t) {
    Test1 a = t; // expected-error{{implicitly-deleted}}
  }

  class Test2 : A {}; // expected-note {{base class 'test6::A' has an inaccessible copy constructor}}
  void test2(const Test2 &t) {
    Test2 a = t; // expected-error{{implicitly-deleted}}
  }
#endif
@


1.1.1.4
log
@Import clang r309604 from branches/release_50
@
text
@d170 1
a170 1
  Derived3 d3; // expected-note 3{{implicit default constructor}}\
@


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


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


1.1.1.2.8.1
log
@file p4.cpp was added on branch tls-maxphys on 2014-08-19 23:47:39 +0000
@
text
@d1 510
@


1.1.1.2.8.2
log
@Rebase to HEAD as of a few days ago.
@
text
@a0 510
// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -fsyntax-only -verify %s

// C++0x [class.access]p4:

//   Access control is applied uniformly to all names, whether the
//   names are referred to from declarations or expressions.  In the
//   case of overloaded function names, access control is applied to
//   the function selected by overload resolution.

class Public {} PublicInst;
class Protected {} ProtectedInst;
class Private {} PrivateInst;

namespace test0 {
  class A {
  public:
    void foo(Public&);
  protected:
    void foo(Protected&); // expected-note 2 {{declared protected here}}
  private:
    void foo(Private&); // expected-note 2 {{declared private here}}
  };

  void test(A *op) {
    op->foo(PublicInst);
    op->foo(ProtectedInst); // expected-error {{'foo' is a protected member}}
    op->foo(PrivateInst); // expected-error {{'foo' is a private member}}

    void (A::*a)(Public&) = &A::foo;
    void (A::*b)(Protected&) = &A::foo; // expected-error {{'foo' is a protected member}}
    void (A::*c)(Private&) = &A::foo; // expected-error {{'foo' is a private member}}
  }
}

// Member operators.
namespace test1 {
  class A {
  public:
    void operator+(Public&);
    void operator[](Public&);
    void operator()(Public&);
    typedef void (*PublicSurrogate)(Public&);
    operator PublicSurrogate() const;
  protected:
    void operator+(Protected&); // expected-note {{declared protected here}}
    void operator[](Protected&); // expected-note {{declared protected here}}
    void operator()(Protected&); // expected-note {{declared protected here}}
    typedef void (*ProtectedSurrogate)(Protected&);
    operator ProtectedSurrogate() const; // expected-note {{declared protected here}}
  private:
    void operator+(Private&); // expected-note {{declared private here}}
    void operator[](Private&); // expected-note {{declared private here}}
    void operator()(Private&); // expected-note {{declared private here}}
    void operator-(); // expected-note {{declared private here}}
    typedef void (*PrivateSurrogate)(Private&);
    operator PrivateSurrogate() const; // expected-note {{declared private here}}
  };
  void operator+(const A &, Public&);
  void operator+(const A &, Protected&);
  void operator+(const A &, Private&);
  void operator-(const A &);

  void test(A &a, Public &pub, Protected &prot, Private &priv) {
    a + pub;
    a + prot; // expected-error {{'operator+' is a protected member}}
    a + priv; // expected-error {{'operator+' is a private member}}
    a[pub];
    a[prot]; // expected-error {{'operator[]' is a protected member}}
    a[priv]; // expected-error {{'operator[]' is a private member}}
    a(pub);
    a(prot); // expected-error {{'operator()' is a protected member}}
    a(priv); // expected-error {{'operator()' is a private member}}
    -a;       // expected-error {{'operator-' is a private member}}

    const A &ca = a;
    ca + pub;
    ca + prot;
    ca + priv;
    -ca;
    // These are all surrogate calls
    ca(pub);
    ca(prot); // expected-error {{'operator void (*)(Protected &)' is a protected member}}
    ca(priv); // expected-error {{'operator void (*)(Private &)' is a private member}}
  }
}

// Implicit constructor calls.
namespace test2 {
  class A {
  private:
    A(); // expected-note 3 {{declared private here}}

    static A foo;
  };

  A a; // expected-error {{calling a private constructor}}
  A A::foo; // okay
  
  class B : A { }; // expected-error {{base class 'test2::A' has private default constructor}}
  B b; // expected-note{{implicit default constructor}}
  
  class C : virtual A { 
  public:
    C();
  };

  class D : C { }; // expected-error {{inherited virtual base class 'test2::A' has private default constructor}}
  D d; // expected-note{{implicit default constructor}}
}

// Implicit destructor calls.
namespace test3 {
  class A {
  private:
    ~A(); // expected-note 2 {{declared private here}}
    static A foo;
  };

  A a; // expected-error {{variable of type 'test3::A' has private destructor}}
  A A::foo;

  void foo(A param) { // okay
    A local; // expected-error {{variable of type 'test3::A' has private destructor}}
  }

  template <unsigned N> class Base { ~Base(); }; // expected-note 14 {{declared private here}}
  class Base2 : virtual Base<2> { ~Base2(); }; // expected-note 3 {{declared private here}} \
                                               // expected-error {{base class 'Base<2>' has private destructor}}
  class Base3 : virtual Base<3> { public: ~Base3(); }; // expected-error {{base class 'Base<3>' has private destructor}}

  // These don't cause diagnostics because we don't need the destructor.
  class Derived0 : Base<0> { ~Derived0(); };
  class Derived1 : Base<1> { };

  class Derived2 : // expected-error {{inherited virtual base class 'Base<2>' has private destructor}} \
                   // expected-error {{inherited virtual base class 'Base<3>' has private destructor}}
    Base<0>,  // expected-error {{base class 'Base<0>' has private destructor}}
    virtual Base<1>, // expected-error {{base class 'Base<1>' has private destructor}}
    Base2, // expected-error {{base class 'test3::Base2' has private destructor}}
    virtual Base3
  {
    ~Derived2() {}
  };

  class Derived3 : // expected-error 2 {{inherited virtual base class 'Base<2>' has private destructor}} \
                   // expected-error 2 {{inherited virtual base class 'Base<3>' has private destructor}} \
    // expected-note 2{{implicit default constructor}}
    Base<0>,  // expected-error 2 {{base class 'Base<0>' has private destructor}}
    virtual Base<1>, // expected-error 2 {{base class 'Base<1>' has private destructor}}
    Base2, // expected-error 2 {{base class 'test3::Base2' has private destructor}}
    virtual Base3
  {}; 
  Derived3 d3; // expected-note {{implicit default constructor}}\
               // expected-note{{implicit destructor}}}
}

// Conversion functions.
namespace test4 {
  class Base {
  private:
    operator Private(); // expected-note 4 {{declared private here}}
  public:
    operator Public(); // expected-note 2{{member is declared here}}
  };

  class Derived1 : private Base { // expected-note 2 {{declared private here}} \
                                  // expected-note {{constrained by private inheritance}}
    Private test1() { return *this; } // expected-error {{'operator Private' is a private member}}
    Public test2() { return *this; }
  };
  Private test1(Derived1 &d) { return d; } // expected-error {{'operator Private' is a private member}} \
                                           // expected-error {{cannot cast 'test4::Derived1' to its private base class}}
  Public test2(Derived1 &d) { return d; } // expected-error {{cannot cast 'test4::Derived1' to its private base class}} \
                                          // expected-error {{'operator Public' is a private member}}


  class Derived2 : public Base {
    Private test1() { return *this; } // expected-error {{'operator Private' is a private member}}
    Public test2() { return *this; }
  };
  Private test1(Derived2 &d) { return d; } // expected-error {{'operator Private' is a private member}}
  Public test2(Derived2 &d) { return d; }

  class Derived3 : private Base { // expected-note {{constrained by private inheritance here}} \
                                  // expected-note {{declared private here}}
  public:
    operator Private();
  };
  Private test1(Derived3 &d) { return d; }
  Public test2(Derived3 &d) { return d; } // expected-error {{'operator Public' is a private member of 'test4::Base'}} \
                                          // expected-error {{cannot cast 'test4::Derived3' to its private base class}}

  class Derived4 : public Base {
  public:
    operator Private();
  };
  Private test1(Derived4 &d) { return d; }
  Public test2(Derived4 &d) { return d; }
}

// Implicit copy assignment operator uses.
namespace test5 {
  class A {
    void operator=(const A &); // expected-note 2 {{implicitly declared private here}}
  };

  class Test1 { A a; }; // expected-error {{private member}}
  void test1() {
    Test1 a; 
    a = Test1(); // expected-note{{implicit copy}}
  }

  class Test2 : A {}; // expected-error {{private member}}
  void test2() {
    Test2 a;
    a = Test2(); // expected-note{{implicit copy}}
  }
}

// Implicit copy constructor uses.
namespace test6 {
  class A {
    public: A();
    private: A(const A &); // expected-note 2 {{declared private here}}
  };

  class Test1 { A a; }; // expected-error {{field of type 'test6::A' has private copy constructor}}
  void test1(const Test1 &t) {
    Test1 a = t; // expected-note{{implicit copy}}
  }

  class Test2 : A {}; // expected-error {{base class 'test6::A' has private copy constructor}}
  void test2(const Test2 &t) {
    Test2 a = t; // expected-note{{implicit copy}}
  }
}

// Redeclaration lookups are not accesses.
namespace test7 {
  class A {
    int private_member;
  };
  class B : A {
    int foo(int private_member) {
      return 0;
    }
  };
}

// Ignored operator new and delete overloads are not 
namespace test8 {
  typedef __typeof__(sizeof(int)) size_t;

  class A {
    void *operator new(size_t s);
    void operator delete(void *p);
  public:
    void *operator new(size_t s, int n);
    void operator delete(void *p, int n);
  };

  void test() {
    new (2) A();
  }
}

// Don't silently upgrade forbidden-access paths to private.
namespace test9 {
  class A {
  public: static int x; // expected-note {{member is declared here}}
  };
  class B : private A { // expected-note {{constrained by private inheritance here}}
  };
  class C : public B {
    static int getX() { return x; } // expected-error {{'x' is a private member of 'test9::A'}}
  };
}

namespace test10 {
  class A {
    enum {
      value = 10 // expected-note {{declared private here}}
    };
    friend class C;
  };

  class B {
    enum {
      value = A::value // expected-error {{'value' is a private member of 'test10::A'}}
    };
  };

  class C {
    enum {
      value = A::value
    };
  };
}

namespace test11 {
  class A {
    protected: virtual ~A();
  };

  class B : public A {
    ~B();
  };

  B::~B() {};
}

namespace test12 {
  class A {
    int x;

    void foo() {
      class Local {
        int foo(A *a) {
          return a->x;
        }
      };
    }
  };
}

namespace test13 {
  struct A {
    int x;
    unsigned foo() const;
  };

  struct B : protected A {
    using A::foo;
    using A::x;
  };

  void test() {
    A *d;
    d->foo();
    (void) d->x;
  }
}

// Destructors for temporaries.
namespace test14 {
  class A {
  private: ~A(); // expected-note {{declared private here}}
  };
  A foo();

  void test() {
    foo(); // expected-error {{temporary of type 'test14::A' has private destructor}}
  }

  class X {
    ~X(); // expected-note {{declared private here}}
  };
  
  struct Y1 {
    operator X();
  };
  
  void g() {
    const X &xr = Y1(); // expected-error{{temporary of type 'test14::X' has private destructor}}
  }
}

// PR 7024
namespace test15 {
  template <class T> class A {
  private:
    int private_foo; // expected-note {{declared private here}}
    static int private_sfoo; // expected-note {{declared private here}}
  protected:
    int protected_foo; // expected-note 3 {{declared protected here}} // expected-note {{can only access this member on an object of type 'test15::B<int>'}}
    static int protected_sfoo; // expected-note 3 {{declared protected here}}

    int test1(A<int> &a) {
      return a.private_foo; // expected-error {{private member}}
    }

    int test2(A<int> &a) {
      return a.private_sfoo; // expected-error {{private member}}
    }

    int test3(A<int> &a) {
      return a.protected_foo; // expected-error {{protected member}}
    }

    int test4(A<int> &a) {
      return a.protected_sfoo; // expected-error {{protected member}}
    }
  };

  template class A<int>;
  template class A<long>; // expected-note 4 {{in instantiation}} 

  template <class T> class B : public A<T> {
    // TODO: These first two accesses can be detected as ill-formed at
    // definition time because they're member accesses and A<int> can't
    // be a subclass of B<T> for any T.

    int test1(A<int> &a) {
      return a.protected_foo; // expected-error 2 {{protected member}}
    }

    int test2(A<int> &a) {
      return a.protected_sfoo; // expected-error {{protected member}}
    }

    int test3(B<int> &b) {
      return b.protected_foo; // expected-error {{protected member}}
    }

    int test4(B<int> &b) {
      return b.protected_sfoo; // expected-error {{protected member}}
    }
  };

  template class B<int>;  // expected-note {{in instantiation}}
  template class B<long>; // expected-note 4 {{in instantiation}}
}

// PR7281
namespace test16 {
  class A { ~A(); }; // expected-note 2{{declared private here}}
  void b() { throw A(); } // expected-error{{temporary of type 'test16::A' has private destructor}} \
  // expected-error{{exception object of type 'test16::A' has private destructor}}
}

// rdar://problem/8146294
namespace test17 {
  class A {
    template <typename T> class Inner { }; // expected-note {{declared private here}}
  };

  A::Inner<int> s; // expected-error {{'Inner' is a private member of 'test17::A'}}
}

namespace test18 {
  template <class T> class A {};
  class B : A<int> {
    A<int> member;
  };

  // FIXME: this access to A should be forbidden (because C++ is dumb),
  // but LookupResult can't express the necessary information to do
  // the check, so we aggressively suppress access control.
  class C : B {
    A<int> member;
  };
}

// PR8325
namespace test19 {
  class A { ~A(); };
  // The destructor is not implicitly referenced here.  Contrast to test16, 
  // testing PR7281, earlier in this file.
  void b(A* x) { throw x; }
}

// PR7930
namespace test20 {
  class Foo {
    Foo(); // expected-note {{implicitly declared private here}}
  };
  Foo::Foo() {}

  void test() {
    Foo a; // expected-error {{calling a private constructor}}
  }
}

namespace test21 {
  template <class T> class A {
    void foo();
    void bar();
    class Inner; // expected-note {{implicitly declared private here}}
  public:
    void baz();
  };
  template <class T> class A<T>::Inner {};
  class B {
    template <class T> class A<T>::Inner; // expected-error{{non-friend class member 'Inner' cannot have a qualified name}}
  };

  void test() {
    A<int>::Inner i; // expected-error {{'Inner' is a private member}}
  }
}

namespace rdar8876150 {
  struct A { operator bool(); };
  struct B : private A { using A::operator bool; };

  bool f() {
    B b;
    return !b;
  }
}

namespace test23 {
  template <typename T> class A {
    A();
    static A instance;
  };

  template <typename T> A<T> A<T>::instance;
  template class A<int>;
}
@


1.1.1.2.4.1
log
@file p4.cpp was added on branch yamt-pagecache on 2014-05-22 16:18:39 +0000
@
text
@d1 510
@


1.1.1.2.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 510
// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -fsyntax-only -verify %s

// C++0x [class.access]p4:

//   Access control is applied uniformly to all names, whether the
//   names are referred to from declarations or expressions.  In the
//   case of overloaded function names, access control is applied to
//   the function selected by overload resolution.

class Public {} PublicInst;
class Protected {} ProtectedInst;
class Private {} PrivateInst;

namespace test0 {
  class A {
  public:
    void foo(Public&);
  protected:
    void foo(Protected&); // expected-note 2 {{declared protected here}}
  private:
    void foo(Private&); // expected-note 2 {{declared private here}}
  };

  void test(A *op) {
    op->foo(PublicInst);
    op->foo(ProtectedInst); // expected-error {{'foo' is a protected member}}
    op->foo(PrivateInst); // expected-error {{'foo' is a private member}}

    void (A::*a)(Public&) = &A::foo;
    void (A::*b)(Protected&) = &A::foo; // expected-error {{'foo' is a protected member}}
    void (A::*c)(Private&) = &A::foo; // expected-error {{'foo' is a private member}}
  }
}

// Member operators.
namespace test1 {
  class A {
  public:
    void operator+(Public&);
    void operator[](Public&);
    void operator()(Public&);
    typedef void (*PublicSurrogate)(Public&);
    operator PublicSurrogate() const;
  protected:
    void operator+(Protected&); // expected-note {{declared protected here}}
    void operator[](Protected&); // expected-note {{declared protected here}}
    void operator()(Protected&); // expected-note {{declared protected here}}
    typedef void (*ProtectedSurrogate)(Protected&);
    operator ProtectedSurrogate() const; // expected-note {{declared protected here}}
  private:
    void operator+(Private&); // expected-note {{declared private here}}
    void operator[](Private&); // expected-note {{declared private here}}
    void operator()(Private&); // expected-note {{declared private here}}
    void operator-(); // expected-note {{declared private here}}
    typedef void (*PrivateSurrogate)(Private&);
    operator PrivateSurrogate() const; // expected-note {{declared private here}}
  };
  void operator+(const A &, Public&);
  void operator+(const A &, Protected&);
  void operator+(const A &, Private&);
  void operator-(const A &);

  void test(A &a, Public &pub, Protected &prot, Private &priv) {
    a + pub;
    a + prot; // expected-error {{'operator+' is a protected member}}
    a + priv; // expected-error {{'operator+' is a private member}}
    a[pub];
    a[prot]; // expected-error {{'operator[]' is a protected member}}
    a[priv]; // expected-error {{'operator[]' is a private member}}
    a(pub);
    a(prot); // expected-error {{'operator()' is a protected member}}
    a(priv); // expected-error {{'operator()' is a private member}}
    -a;       // expected-error {{'operator-' is a private member}}

    const A &ca = a;
    ca + pub;
    ca + prot;
    ca + priv;
    -ca;
    // These are all surrogate calls
    ca(pub);
    ca(prot); // expected-error {{'operator void (*)(Protected &)' is a protected member}}
    ca(priv); // expected-error {{'operator void (*)(Private &)' is a private member}}
  }
}

// Implicit constructor calls.
namespace test2 {
  class A {
  private:
    A(); // expected-note 3 {{declared private here}}

    static A foo;
  };

  A a; // expected-error {{calling a private constructor}}
  A A::foo; // okay
  
  class B : A { }; // expected-error {{base class 'test2::A' has private default constructor}}
  B b; // expected-note{{implicit default constructor}}
  
  class C : virtual A { 
  public:
    C();
  };

  class D : C { }; // expected-error {{inherited virtual base class 'test2::A' has private default constructor}}
  D d; // expected-note{{implicit default constructor}}
}

// Implicit destructor calls.
namespace test3 {
  class A {
  private:
    ~A(); // expected-note 2 {{declared private here}}
    static A foo;
  };

  A a; // expected-error {{variable of type 'test3::A' has private destructor}}
  A A::foo;

  void foo(A param) { // okay
    A local; // expected-error {{variable of type 'test3::A' has private destructor}}
  }

  template <unsigned N> class Base { ~Base(); }; // expected-note 14 {{declared private here}}
  class Base2 : virtual Base<2> { ~Base2(); }; // expected-note 3 {{declared private here}} \
                                               // expected-error {{base class 'Base<2>' has private destructor}}
  class Base3 : virtual Base<3> { public: ~Base3(); }; // expected-error {{base class 'Base<3>' has private destructor}}

  // These don't cause diagnostics because we don't need the destructor.
  class Derived0 : Base<0> { ~Derived0(); };
  class Derived1 : Base<1> { };

  class Derived2 : // expected-error {{inherited virtual base class 'Base<2>' has private destructor}} \
                   // expected-error {{inherited virtual base class 'Base<3>' has private destructor}}
    Base<0>,  // expected-error {{base class 'Base<0>' has private destructor}}
    virtual Base<1>, // expected-error {{base class 'Base<1>' has private destructor}}
    Base2, // expected-error {{base class 'test3::Base2' has private destructor}}
    virtual Base3
  {
    ~Derived2() {}
  };

  class Derived3 : // expected-error 2 {{inherited virtual base class 'Base<2>' has private destructor}} \
                   // expected-error 2 {{inherited virtual base class 'Base<3>' has private destructor}} \
    // expected-note 2{{implicit default constructor}}
    Base<0>,  // expected-error 2 {{base class 'Base<0>' has private destructor}}
    virtual Base<1>, // expected-error 2 {{base class 'Base<1>' has private destructor}}
    Base2, // expected-error 2 {{base class 'test3::Base2' has private destructor}}
    virtual Base3
  {}; 
  Derived3 d3; // expected-note {{implicit default constructor}}\
               // expected-note{{implicit destructor}}}
}

// Conversion functions.
namespace test4 {
  class Base {
  private:
    operator Private(); // expected-note 4 {{declared private here}}
  public:
    operator Public(); // expected-note 2{{member is declared here}}
  };

  class Derived1 : private Base { // expected-note 2 {{declared private here}} \
                                  // expected-note {{constrained by private inheritance}}
    Private test1() { return *this; } // expected-error {{'operator Private' is a private member}}
    Public test2() { return *this; }
  };
  Private test1(Derived1 &d) { return d; } // expected-error {{'operator Private' is a private member}} \
                                           // expected-error {{cannot cast 'test4::Derived1' to its private base class}}
  Public test2(Derived1 &d) { return d; } // expected-error {{cannot cast 'test4::Derived1' to its private base class}} \
                                          // expected-error {{'operator Public' is a private member}}


  class Derived2 : public Base {
    Private test1() { return *this; } // expected-error {{'operator Private' is a private member}}
    Public test2() { return *this; }
  };
  Private test1(Derived2 &d) { return d; } // expected-error {{'operator Private' is a private member}}
  Public test2(Derived2 &d) { return d; }

  class Derived3 : private Base { // expected-note {{constrained by private inheritance here}} \
                                  // expected-note {{declared private here}}
  public:
    operator Private();
  };
  Private test1(Derived3 &d) { return d; }
  Public test2(Derived3 &d) { return d; } // expected-error {{'operator Public' is a private member of 'test4::Base'}} \
                                          // expected-error {{cannot cast 'test4::Derived3' to its private base class}}

  class Derived4 : public Base {
  public:
    operator Private();
  };
  Private test1(Derived4 &d) { return d; }
  Public test2(Derived4 &d) { return d; }
}

// Implicit copy assignment operator uses.
namespace test5 {
  class A {
    void operator=(const A &); // expected-note 2 {{implicitly declared private here}}
  };

  class Test1 { A a; }; // expected-error {{private member}}
  void test1() {
    Test1 a; 
    a = Test1(); // expected-note{{implicit copy}}
  }

  class Test2 : A {}; // expected-error {{private member}}
  void test2() {
    Test2 a;
    a = Test2(); // expected-note{{implicit copy}}
  }
}

// Implicit copy constructor uses.
namespace test6 {
  class A {
    public: A();
    private: A(const A &); // expected-note 2 {{declared private here}}
  };

  class Test1 { A a; }; // expected-error {{field of type 'test6::A' has private copy constructor}}
  void test1(const Test1 &t) {
    Test1 a = t; // expected-note{{implicit copy}}
  }

  class Test2 : A {}; // expected-error {{base class 'test6::A' has private copy constructor}}
  void test2(const Test2 &t) {
    Test2 a = t; // expected-note{{implicit copy}}
  }
}

// Redeclaration lookups are not accesses.
namespace test7 {
  class A {
    int private_member;
  };
  class B : A {
    int foo(int private_member) {
      return 0;
    }
  };
}

// Ignored operator new and delete overloads are not 
namespace test8 {
  typedef __typeof__(sizeof(int)) size_t;

  class A {
    void *operator new(size_t s);
    void operator delete(void *p);
  public:
    void *operator new(size_t s, int n);
    void operator delete(void *p, int n);
  };

  void test() {
    new (2) A();
  }
}

// Don't silently upgrade forbidden-access paths to private.
namespace test9 {
  class A {
  public: static int x; // expected-note {{member is declared here}}
  };
  class B : private A { // expected-note {{constrained by private inheritance here}}
  };
  class C : public B {
    static int getX() { return x; } // expected-error {{'x' is a private member of 'test9::A'}}
  };
}

namespace test10 {
  class A {
    enum {
      value = 10 // expected-note {{declared private here}}
    };
    friend class C;
  };

  class B {
    enum {
      value = A::value // expected-error {{'value' is a private member of 'test10::A'}}
    };
  };

  class C {
    enum {
      value = A::value
    };
  };
}

namespace test11 {
  class A {
    protected: virtual ~A();
  };

  class B : public A {
    ~B();
  };

  B::~B() {};
}

namespace test12 {
  class A {
    int x;

    void foo() {
      class Local {
        int foo(A *a) {
          return a->x;
        }
      };
    }
  };
}

namespace test13 {
  struct A {
    int x;
    unsigned foo() const;
  };

  struct B : protected A {
    using A::foo;
    using A::x;
  };

  void test() {
    A *d;
    d->foo();
    (void) d->x;
  }
}

// Destructors for temporaries.
namespace test14 {
  class A {
  private: ~A(); // expected-note {{declared private here}}
  };
  A foo();

  void test() {
    foo(); // expected-error {{temporary of type 'test14::A' has private destructor}}
  }

  class X {
    ~X(); // expected-note {{declared private here}}
  };
  
  struct Y1 {
    operator X();
  };
  
  void g() {
    const X &xr = Y1(); // expected-error{{temporary of type 'test14::X' has private destructor}}
  }
}

// PR 7024
namespace test15 {
  template <class T> class A {
  private:
    int private_foo; // expected-note {{declared private here}}
    static int private_sfoo; // expected-note {{declared private here}}
  protected:
    int protected_foo; // expected-note 3 {{declared protected here}} // expected-note {{can only access this member on an object of type 'test15::B<int>'}}
    static int protected_sfoo; // expected-note 3 {{declared protected here}}

    int test1(A<int> &a) {
      return a.private_foo; // expected-error {{private member}}
    }

    int test2(A<int> &a) {
      return a.private_sfoo; // expected-error {{private member}}
    }

    int test3(A<int> &a) {
      return a.protected_foo; // expected-error {{protected member}}
    }

    int test4(A<int> &a) {
      return a.protected_sfoo; // expected-error {{protected member}}
    }
  };

  template class A<int>;
  template class A<long>; // expected-note 4 {{in instantiation}} 

  template <class T> class B : public A<T> {
    // TODO: These first two accesses can be detected as ill-formed at
    // definition time because they're member accesses and A<int> can't
    // be a subclass of B<T> for any T.

    int test1(A<int> &a) {
      return a.protected_foo; // expected-error 2 {{protected member}}
    }

    int test2(A<int> &a) {
      return a.protected_sfoo; // expected-error {{protected member}}
    }

    int test3(B<int> &b) {
      return b.protected_foo; // expected-error {{protected member}}
    }

    int test4(B<int> &b) {
      return b.protected_sfoo; // expected-error {{protected member}}
    }
  };

  template class B<int>;  // expected-note {{in instantiation}}
  template class B<long>; // expected-note 4 {{in instantiation}}
}

// PR7281
namespace test16 {
  class A { ~A(); }; // expected-note 2{{declared private here}}
  void b() { throw A(); } // expected-error{{temporary of type 'test16::A' has private destructor}} \
  // expected-error{{exception object of type 'test16::A' has private destructor}}
}

// rdar://problem/8146294
namespace test17 {
  class A {
    template <typename T> class Inner { }; // expected-note {{declared private here}}
  };

  A::Inner<int> s; // expected-error {{'Inner' is a private member of 'test17::A'}}
}

namespace test18 {
  template <class T> class A {};
  class B : A<int> {
    A<int> member;
  };

  // FIXME: this access to A should be forbidden (because C++ is dumb),
  // but LookupResult can't express the necessary information to do
  // the check, so we aggressively suppress access control.
  class C : B {
    A<int> member;
  };
}

// PR8325
namespace test19 {
  class A { ~A(); };
  // The destructor is not implicitly referenced here.  Contrast to test16, 
  // testing PR7281, earlier in this file.
  void b(A* x) { throw x; }
}

// PR7930
namespace test20 {
  class Foo {
    Foo(); // expected-note {{implicitly declared private here}}
  };
  Foo::Foo() {}

  void test() {
    Foo a; // expected-error {{calling a private constructor}}
  }
}

namespace test21 {
  template <class T> class A {
    void foo();
    void bar();
    class Inner; // expected-note {{implicitly declared private here}}
  public:
    void baz();
  };
  template <class T> class A<T>::Inner {};
  class B {
    template <class T> class A<T>::Inner; // expected-error{{non-friend class member 'Inner' cannot have a qualified name}}
  };

  void test() {
    A<int>::Inner i; // expected-error {{'Inner' is a private member}}
  }
}

namespace rdar8876150 {
  struct A { operator bool(); };
  struct B : private A { using A::operator bool; };

  bool f() {
    B b;
    return !b;
  }
}

namespace test23 {
  template <typename T> class A {
    A();
    static A instance;
  };

  template <typename T> A<T> A<T>::instance;
  template class A<int>;
}
@


