From Jason Turner

[namespace.memdef]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmp1ldf632c/{from.md → to.md} +0 -118
tmp/tmp1ldf632c/{from.md → to.md} RENAMED
@@ -1,118 +0,0 @@
1
- #### Namespace member definitions <a id="namespace.memdef">[[namespace.memdef]]</a>
2
-
3
- A declaration in a namespace `N` (excluding declarations in nested
4
- scopes) whose *declarator-id* is an *unqualified-id* [[dcl.meaning]],
5
- whose *class-head-name* [[class.pre]] or *enum-head-name* [[dcl.enum]]
6
- is an *identifier*, or whose *elaborated-type-specifier* is of the form
7
- *class-key* *attribute-specifier-seq*ₒₚₜ *identifier*
8
- [[dcl.type.elab]], or that is an *opaque-enum-declaration*, declares (or
9
- redeclares) its *unqualified-id* or *identifier* as a member of `N`.
10
-
11
- [*Note 1*: An explicit instantiation [[temp.explicit]] or explicit
12
- specialization [[temp.expl.spec]] of a template does not introduce a
13
- name and thus may be declared using an *unqualified-id* in a member of
14
- the enclosing namespace set, if the primary template is declared in an
15
- inline namespace. — *end note*]
16
-
17
- [*Example 1*:
18
-
19
- ``` cpp
20
- namespace X {
21
- void f() { ... } // OK: introduces X::f()
22
-
23
- namespace M {
24
- void g(); // OK: introduces X::M::g()
25
- }
26
- using M::g;
27
- void g(); // error: conflicts with X::M::g()
28
- }
29
- ```
30
-
31
- — *end example*]
32
-
33
- Members of a named namespace can also be defined outside that namespace
34
- by explicit qualification [[namespace.qual]] of the name being defined,
35
- provided that the entity being defined was already declared in the
36
- namespace and the definition appears after the point of declaration in a
37
- namespace that encloses the declaration’s namespace.
38
-
39
- [*Example 2*:
40
-
41
- ``` cpp
42
- namespace Q {
43
- namespace V {
44
- void f();
45
- }
46
- void V::f() { ... } // OK
47
- void V::g() { ... } // error: g() is not yet a member of V
48
- namespace V {
49
- void g();
50
- }
51
- }
52
-
53
- namespace R {
54
- void Q::V::g() { ... } // error: R doesn't enclose Q
55
- }
56
- ```
57
-
58
- — *end example*]
59
-
60
- If a friend declaration in a non-local class first declares a class,
61
- function, class template or function template[^10] the friend is a
62
- member of the innermost enclosing namespace. The friend declaration does
63
- not by itself make the name visible to unqualified lookup
64
- [[basic.lookup.unqual]] or qualified lookup [[basic.lookup.qual]].
65
-
66
- [*Note 2*: The name of the friend will be visible in its namespace if a
67
- matching declaration is provided at namespace scope (either before or
68
- after the class definition granting friendship). — *end note*]
69
-
70
- If a friend function or function template is called, its name may be
71
- found by the name lookup that considers functions from namespaces and
72
- classes associated with the types of the function arguments
73
- [[basic.lookup.argdep]]. If the name in a friend declaration is neither
74
- qualified nor a *template-id* and the declaration is a function or an
75
- *elaborated-type-specifier*, the lookup to determine whether the entity
76
- has been previously declared shall not consider any scopes outside the
77
- innermost enclosing namespace.
78
-
79
- [*Note 3*: The other forms of friend declarations cannot declare a new
80
- member of the innermost enclosing namespace and thus follow the usual
81
- lookup rules. — *end note*]
82
-
83
- [*Example 3*:
84
-
85
- ``` cpp
86
- // Assume f and g have not yet been declared.
87
- void h(int);
88
- template <class T> void f2(T);
89
- namespace A {
90
- class X {
91
- friend void f(X); // A::f(X) is a friend
92
- class Y {
93
- friend void g(); // A::g is a friend
94
- friend void h(int); // A::h is a friend
95
- // ::h not considered
96
- friend void f2<>(int); // ::f2<>(int) is a friend
97
- };
98
- };
99
-
100
- // A::f, A::g and A::h are not visible here
101
- X x;
102
- void g() { f(x); } // definition of A::g
103
- void f(X) { ... } // definition of A::f
104
- void h(int) { ... } // definition of A::h
105
- // A::f, A::g and A::h are visible here and known to be friends
106
- }
107
-
108
- using A::x;
109
-
110
- void h() {
111
- A::f(x);
112
- A::X::f(x); // error: f is not a member of A::X
113
- A::X::Y::g(); // error: g is not a member of A::X::Y
114
- }
115
- ```
116
-
117
- — *end example*]
118
-