1 // RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
4 struct S; // expected-note {{previously declared 'private' here}}
7 struct S {}; // expected-error {{'S' redeclared with 'public' access}}
11 class C; // expected-note {{previously declared 'public' here}}
14 class C { }; // expected-error {{'C' redeclared with 'private' access}}
19 template<typename T> struct A; // expected-note {{previously declared 'protected' here}}
22 template<typename T> struct A {}; // expected-error {{'A' redeclared with 'private' access}}
29 class X; // expected-note {{previously declared 'private' here}} \
30 // expected-note {{previous declaration is here}}
32 class X; // expected-error {{'X' redeclared with 'public' access}} \
33 // expected-warning {{class member cannot be redeclared}}
40 namespace alias_templates {
41 template<typename T1, typename T2> struct U { };
42 template<typename T1> using W = U<T1, float>;
46 static constexpr I x = 0; // expected-note {{implicitly declared private here}}
47 static constexpr I y = 42; // expected-note {{implicitly declared private here}}
54 // the following will trigger for U<float, float> instantiation, via W<float>
55 U() : v_(A::x) { } // expected-error {{'x' is a private member of 'PR15209::alias_templates::A'}}
61 U() : v_(A::y) { } // expected-error {{'y' is a private member of 'PR15209::alias_templates::A'}}
64 template struct U<int, int>; // expected-note {{in instantiation of member function 'PR15209::alias_templates::U<int, int>::U' requested here}}
69 // we should issue diagnostics for the following
70 W<float>(); // expected-note {{in instantiation of member function 'PR15209::alias_templates::U<float, float>::U' requested here}}
76 typedef int I; // expected-note {{implicitly declared private here}}
77 static constexpr I x = 0; // expected-note {{implicitly declared private here}}
79 template<int> friend struct B;
80 template<int> struct C;
81 template<template<int> class T> friend struct TT;
82 template<typename T> friend void funct(T);
84 template<A::I> struct B { };
86 template<A::I> struct A::C { };
88 template<template<A::I> class T> struct TT {
92 template struct TT<B>;
93 template<A::I> struct D { }; // expected-error {{'I' is a private member of 'PR15209::templates::A'}}
94 template struct TT<D>;
96 // function template case
103 template void funct<int>(int);
107 (void)A::x; // expected-error {{'x' is a private member of 'PR15209::templates::A'}}
114 template <typename T> struct X;
117 template<typename T> friend struct X;
118 int t; // expected-note {{here}}
121 template<typename T> struct X {
122 X() { (void)N::Y().t; } // expected-error {{private}}
131 int t; // expected-note {{here}}
135 X() { (void)N::Y().t; } // expected-error {{private}}
140 namespace LocalExternVar {
143 struct private_struct { // expected-note 2{{here}}
149 int test::use_private() {
150 extern int array[sizeof(test::private_struct)]; // ok
155 extern int array[sizeof(test::private_struct)]; // expected-error {{private}}
159 int array[sizeof(test::private_struct)]; // expected-error {{private}}
162 namespace ThisLambdaIsNotMyFriend {
165 static void foo(); // expected-note {{here}}
167 template <class T> void foo() {
168 []() { A::foo(); }(); // expected-error {{private}}
170 void bar() { foo<void>(); }
173 namespace OverloadedMemberFunctionPointer {
174 template<class T, void(T::*pMethod)()>
177 template<class T, void(T::*pMethod)(int)>
181 void func2(void(*fn)()) {} // expected-note 2 {{candidate function template not viable: no overload of 'func}}
185 friend void friendFunc();
186 void overloadedMethod();
188 void overloadedMethod(int);
190 void overloadedMethod(int, int);
192 func2<int>(&func0<C, &C::overloadedMethod>);
193 func2<int>(&func1<C, &C::overloadedMethod>);
198 func2<int>(&func0<C, &C::overloadedMethod>);
199 func2<int>(&func1<C, &C::overloadedMethod>);
202 void nonFriendFunc() {
203 func2<int>(&func0<C, &C::overloadedMethod>); // expected-error {{no matching function for call to 'func2'}}
204 func2<int>(&func1<C, &C::overloadedMethod>); // expected-error {{no matching function for call to 'func2'}}
207 // r325321 caused an assertion failure when the following code was compiled.
209 template <typename Type> static bool foo1() { return true; }