1 // RUN: %clang_cc1 -fsyntax-only %s -verify
3 // C++'0x [namespace.memdef] p3:
4 // Every name first declared in a namespace is a member of that namespace. If
5 // a friend declaration in a non-local class first declares a class or
6 // function the friend class or function is a member of the innermost
7 // enclosing namespace.
13 struct F0
member_func();
16 F0
f0() { return S0().member_func(); }
18 N::F0 f0_var
= N::f0();
20 // Ensure we can handle attaching friend declarations to an enclosing namespace
21 // with multiple contexts.
22 namespace N
{ struct S1
{ struct IS1
; }; }
27 struct F1
member_func();
30 F1
f1() { return S1::IS1().member_func(); }
32 N::F1 f1_var
= N::f1();
34 // The name of the friend is not found by unqualified lookup (3.4.1) or by
35 // qualified lookup (3.4.3) until a matching declaration is provided in that
36 // namespace scope (either before or after the class definition granting
37 // friendship). If a friend function is called, its name may be found by the
38 // name lookup that considers functions from namespaces and classes
39 // associated with the types of the function arguments (3.4.2). If the name
40 // in a friend declaration is neither qualified nor a template-id and the
41 // declaration is a function or an elaborated-type-specifier, the lookup to
42 // determine whether the entity has been previously declared shall not
43 // consider any scopes outside the innermost enclosing namespace.
45 template<typename T
> struct X0
{ };
49 template<typename T
> union X0
;
50 template<typename T
> friend union X0
;
58 template<typename T
> class X
;
64 template<typename T
> friend class N::M::X
;
68 // FIXME: Woefully inadequate for testing
70 // Friends declared as template-ids aren't subject to the restriction
71 // on innermost namespaces.
73 template <class T
> void f(T
);
76 friend void f
<int>(int);
77 static void foo(); // expected-note 2 {{declared private here}}
80 // Note that this happens without instantiation.
81 template <class T
> void f(T
) {
82 A::foo(); // expected-error {{'foo' is a private member of 'test5::ns::A'}}
86 template <class T
> void f(T
) {
87 ns::A::foo(); // expected-error {{'foo' is a private member of 'test5::ns::A'}}
90 template void f
<int>(int);
91 template void f
<long>(long); //expected-note {{instantiation}}
98 static void foo(); // expected-note {{implicitly declared private here}}
111 ns::B::foo(); // expected-error {{'foo' is a private member of 'test6::ns::B'}}
116 // We seem to be following a correct interpretation with these, but
117 // the standard could probably be a bit clearer.
158 // ns1::A appears as if declared in test7c according to [namespace.udir]p2.
159 // I think that means we aren't supposed to find it.
162 static void foo(); // expected-note {{implicitly declared private here}}
169 ns2::B::foo(); // expected-error {{'foo' is a private member of 'test7c::ns2::B'}}
179 // Honor the lexical context of a using-declaration, though.