From Jason Turner

[namespace.memdef]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpqk_utdki/{from.md → to.md} +55 -24
tmp/tmpqk_utdki/{from.md → to.md} RENAMED
@@ -1,59 +1,88 @@
1
  #### Namespace member definitions <a id="namespace.memdef">[[namespace.memdef]]</a>
2
 
3
- Members (including explicit specializations of templates (
4
- [[temp.expl.spec]])) of a namespace can be defined within that
5
- namespace.
 
 
 
 
 
 
 
 
 
 
 
 
6
 
7
  ``` cpp
8
  namespace X {
9
- void f() { /* ... */ }
 
 
 
 
 
 
10
  }
11
  ```
12
 
 
 
13
  Members of a named namespace can also be defined outside that namespace
14
  by explicit qualification ([[namespace.qual]]) of the name being
15
  defined, provided that the entity being defined was already declared in
16
  the namespace and the definition appears after the point of declaration
17
  in a namespace that encloses the declaration’s namespace.
18
 
 
 
19
  ``` cpp
20
  namespace Q {
21
  namespace V {
22
  void f();
23
  }
24
- void V::f() { /* ... */ } // OK
25
- void V::g() { /* ... */ } // error: g() is not yet a member of V
26
  namespace V {
27
  void g();
28
  }
29
  }
30
 
31
  namespace R {
32
- void Q::V::g() { /* ... */ } // error: R doesn't enclose Q
33
  }
34
  ```
35
 
36
- Every name first declared in a namespace is a member of that namespace.
 
37
  If a `friend` declaration in a non-local class first declares a class,
38
- function, class template or function template[^6] the friend is a member
39
  of the innermost enclosing namespace. The `friend` declaration does not
40
  by itself make the name visible to unqualified lookup (
41
  [[basic.lookup.unqual]]) or qualified lookup ([[basic.lookup.qual]]).
42
- The name of the friend will be visible in its namespace if a matching
43
- declaration is provided at namespace scope (either before or after the
44
- class definition granting friendship). If a friend function or function
45
- template is called, its name may be found by the name lookup that
46
- considers functions from namespaces and classes associated with the
47
- types of the function arguments ([[basic.lookup.argdep]]). If the name
48
- in a `friend` declaration is neither qualified nor a *template-id* and
49
- the declaration is a function or an *elaborated-type-specifier*, the
50
- lookup to determine whether the entity has been previously declared
51
- shall not consider any scopes outside the innermost enclosing namespace.
52
- The other forms of `friend` declarations cannot declare a new member of
53
- the innermost enclosing namespace and thus follow the usual lookup
54
- rules.
 
 
 
 
 
 
55
 
56
  ``` cpp
57
  // Assume f and g have not yet been declared.
58
  void h(int);
59
  template <class T> void f2(T);
@@ -69,12 +98,12 @@ namespace A {
69
  };
70
 
71
  // A::f, A::g and A::h are not visible here
72
  X x;
73
  void g() { f(x); } // definition of A::g
74
- void f(X) { /* ... */} // definition of A::f
75
- void h(int) { /* ... */ } // definition of A::h
76
  // A::f, A::g and A::h are visible here and known to be friends
77
  }
78
 
79
  using A::x;
80
 
@@ -83,5 +112,7 @@ void h() {
83
  A::X::f(x); // error: f is not a member of A::X
84
  A::X::Y::g(); // error: g is not a member of A::X::Y
85
  }
86
  ```
87
 
 
 
 
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* (Clause [[class]]) or *enum-head-name* (
6
+ [[dcl.enum]]) is an *identifier*, or whose *elaborated-type-specifier*
7
+ is of the form *class-key* *attribute-specifier-seq*ₒₚₜ *identifier* (
8
+ [[dcl.type.elab]]), or that is an *opaque-enum-declaration*, declares
9
+ (or 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
35
  defined, provided that the entity being defined was already declared in
36
  the namespace and the definition appears after the point of declaration
37
  in a 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[^5] the friend is a member
62
  of the innermost enclosing namespace. The `friend` declaration does not
63
  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
74
+ neither qualified nor a *template-id* and the declaration is a function
75
+ or an *elaborated-type-specifier*, the lookup to determine whether the
76
+ entity has been previously declared shall not consider any scopes
77
+ outside the innermost enclosing namespace.
78
+
79
+ [*Note 3*: The other forms of `friend` declarations cannot declare a
80
+ new member of the innermost enclosing namespace and thus follow the
81
+ usual 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);
 
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
 
 
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
+