// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s class C { struct S; // expected-note {{previously declared 'private' here}} public: struct S {}; // expected-error {{'S' redeclared with 'public' access}} }; struct S { class C; // expected-note {{previously declared 'public' here}} private: class C { }; // expected-error {{'C' redeclared with 'private' access}} }; class T { protected: template struct A; // expected-note {{previously declared 'protected' here}} private: template struct A {}; // expected-error {{'A' redeclared with 'private' access}} }; // PR5573 namespace test1 { class A { private: class X; // expected-note {{previously declared 'private' here}} \ // expected-note {{previous declaration is here}} public: class X; // expected-error {{'X' redeclared with 'public' access}} \ // expected-warning {{class member cannot be redeclared}} class X {}; }; } // PR15209 namespace PR15209 { namespace alias_templates { template struct U { }; template using W = U; class A { typedef int I; static constexpr I x = 0; // expected-note {{implicitly declared private here}} static constexpr I y = 42; // expected-note {{implicitly declared private here}} friend W; }; template struct U { int v_; // the following will trigger for U instantiation, via W U() : v_(A::x) { } // expected-error {{'x' is a private member of 'PR15209::alias_templates::A'}} }; template struct U { int v_; U() : v_(A::y) { } // expected-error {{'y' is a private member of 'PR15209::alias_templates::A'}} }; template struct U; // expected-note {{in instantiation of member function 'PR15209::alias_templates::U::U' requested here}} void f() { W(); // we should issue diagnostics for the following W(); // expected-note {{in instantiation of member function 'PR15209::alias_templates::U::U' requested here}} } } namespace templates { class A { typedef int I; // expected-note {{implicitly declared private here}} static constexpr I x = 0; // expected-note {{implicitly declared private here}} template friend struct B; template struct C; template class T> friend struct TT; template friend void funct(T); }; template struct B { }; template struct A::C { }; template class T> struct TT { T t; }; template struct TT; template struct D { }; // expected-error {{'I' is a private member of 'PR15209::templates::A'}} template struct TT; // function template case template void funct(T) { (void)A::x; } template void funct(int); void f() { (void)A::x; // expected-error {{'x' is a private member of 'PR15209::templates::A'}} } } } namespace PR7434 { namespace comment0 { template struct X; namespace N { class Y { template friend struct X; int t; // expected-note {{here}} }; } template struct X { X() { (void)N::Y().t; } // expected-error {{private}} }; X x; } namespace comment2 { struct X; namespace N { class Y { friend struct X; int t; // expected-note {{here}} }; } struct X { X() { (void)N::Y().t; } // expected-error {{private}} }; } } namespace LocalExternVar { class test { private: struct private_struct { // expected-note 2{{here}} int x; }; int use_private(); }; int test::use_private() { extern int array[sizeof(test::private_struct)]; // ok return array[0]; } int f() { extern int array[sizeof(test::private_struct)]; // expected-error {{private}} return array[0]; } int array[sizeof(test::private_struct)]; // expected-error {{private}} } namespace ThisLambdaIsNotMyFriend { class A { friend class D; static void foo(); // expected-note {{here}} }; template void foo() { []() { A::foo(); }(); // expected-error {{private}} } void bar() { foo(); } } namespace OverloadedMemberFunctionPointer { template void func0() {} template void func1() {} template void func2(void(*fn)()) {} // expected-note 2 {{candidate function template not viable: no overload of 'func}} class C { private: friend void friendFunc(); void overloadedMethod(); protected: void overloadedMethod(int); public: void overloadedMethod(int, int); void method() { func2(&func0); func2(&func1); } }; void friendFunc() { func2(&func0); func2(&func1); } void nonFriendFunc() { func2(&func0); // expected-error {{no matching function for call to 'func2'}} func2(&func1); // expected-error {{no matching function for call to 'func2'}} } // r325321 caused an assertion failure when the following code was compiled. class A { template static bool foo1() { return true; } public: void init(bool c) { if (c) { auto f = foo1; } } }; }