1 // RUN: %clang_cc1 -faccess-control -verify -emit-llvm-only %s
4 template <typename T> struct Num {
8 Num(T value) : value_(value) {}
9 T get() const { return value_; }
11 template <typename U> struct Rep {
13 Rep(U count) : count_(count) {}
15 friend Num operator*(const Num &a, const Rep &n) {
17 for (U count = n.count_; count; --count)
23 friend Num operator+(const Num &a, const Num &b) {
24 return a.value_ + b.value_;
27 Num& operator+=(const Num& b) {
32 class Representation {};
33 friend class Representation;
37 template <typename T> friend bool iszero(const A &a) throw();
40 template <class T> class B_iterator;
41 template <class T> class B {
42 friend class B_iterator<T>;
48 Num<int> result = left + right;
54 Num<int>::Rep<char> n = (char) 10;
55 Num<int> result = x * n;
60 // Reduced from GNU <locale>
63 bool b; // expected-note {{declared private here}}
64 template <typename T> friend bool has(const A&);
66 template <typename T> bool has(const A &x) {
69 template <typename T> bool hasnot(const A &x) {
70 return x.b; // expected-error {{'b' is a private member of 'test1::A'}}
76 bool b; // expected-note {{declared private here}}
77 template <typename T> friend class HasChecker;
79 template <typename T> class HasChecker {
84 template <typename T> class HasNotChecker {
86 return a->b; // expected-error {{'b' is a private member of 'test2::A'}}
93 template <class T> class User;
94 template <class T> T transform(class Bool, T);
97 friend class User<bool>;
98 friend bool transform<>(Bool, bool);
100 bool value; // expected-note 2 {{declared private here}}
103 template <class T> class User {
104 static T compute(Bool b) {
105 return b.value; // expected-error {{'value' is a private member of 'test3::Bool'}}
109 template <class T> T transform(Bool b, T value) {
110 if (b.value) // expected-error {{'value' is a private member of 'test3::Bool'}}
115 template bool transform(Bool, bool);
116 template int transform(Bool, int); // expected-note {{requested here}}
118 template class User<bool>;
119 template class User<int>; // expected-note {{requested here}}
123 template <class T> class A {
124 template <class T0> friend class B;
125 bool foo(const A<T> *) const;
128 template <class T> class B {
129 bool bar(const A<T> *a, const A<T> *b) {
134 template class B<int>;
138 template <class T, class U=int> class A {};
139 template <class T> class B {
140 template <class X, class Y> friend class A;
142 template class B<int>;
143 template class A<int>;
146 namespace Dependent {
147 template<typename T, typename Traits> class X;
148 template<typename T, typename Traits>
149 X<T, Traits> operator+(const X<T, Traits>&, const T*);
151 template<typename T, typename Traits> class X {
152 typedef typename Traits::value_type value_type;
153 friend X operator+<>(const X&, const value_type*);
158 template <class T> class A { // expected-note {{previous definition is here}}
160 int x; // expected-note {{declared private here}}
171 return a.x; // expected-error {{'x' is a private member of 'test7::A<int>'}}
175 // This shouldn't crash.
176 template <class T> class D {
177 friend class A; // expected-error {{redefinition of 'A' as different kind of symbol}}
179 template class D<int>;
183 template <class N> class A {
185 template <class T> friend void foo();
187 template class A<int>;
189 template <class T> void foo() {
192 template void foo<int>();
196 template <class T> class A {
204 return c->x; // expected-error {{'x' is a private member}}
209 friend int A::foo(B*);
213 int x; // expected-note {{declared private here}}
217 template class A<int>; // expected-note {{in instantiation}}