From Jason Turner

[basic.scope.namespace]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpugk9cb67/{from.md → to.md} +11 -88
tmp/tmpugk9cb67/{from.md → to.md} RENAMED
@@ -1,100 +1,23 @@
1
  ### Namespace scope <a id="basic.scope.namespace">[[basic.scope.namespace]]</a>
2
 
3
- The declarative region of a *namespace-definition* is its
4
- *namespace-body*. Entities declared in a *namespace-body* are said to be
5
- *members* of the namespace, and names introduced by these declarations
6
- into the declarative region of the namespace are said to be *member
7
- names* of the namespace. A namespace member name has namespace scope.
8
- Its potential scope includes its namespace from the name’s point of
9
- declaration [[basic.scope.pdecl]] onwards; and for each
10
- *using-directive* [[namespace.udir]] that nominates the member’s
11
- namespace, the member’s potential scope includes that portion of the
12
- potential scope of the *using-directive* that follows the member’s point
13
- of declaration.
14
 
15
  [*Example 1*:
16
 
17
  ``` cpp
18
- namespace N {
19
- int i;
20
- int g(int a) { return a; }
21
- int j();
22
- void q();
23
  }
24
- namespace { int l=1; }
25
- // the potential scope of l is from its point of declaration to the end of the translation unit
26
-
27
- namespace N {
28
- int g(char a) { // overloads N::g(int)
29
- return l+a; // l is from unnamed namespace
30
- }
31
-
32
- int i; // error: duplicate definition
33
- int j(); // OK: duplicate function declaration
34
-
35
- int j() { // OK: definition of N::j()
36
- return g(i); // calls N::g(int)
37
- }
38
- int q(); // error: different return type
39
  }
40
  ```
41
 
42
  — *end example*]
43
 
44
- If a translation unit Q is imported into a translation unit R
45
- [[module.import]], the potential scope of a name X declared with
46
- namespace scope in Q is extended to include the portion of the
47
- corresponding namespace scope in R following the first
48
- *module-import-declaration* or *module-declaration* in R that imports Q
49
- (directly or indirectly) if
50
-
51
- - X does not have internal linkage, and
52
- - X is declared after the *module-declaration* in Q (if any), and
53
- - either X is exported or Q and R are part of the same module.
54
-
55
- [*Note 1*:
56
-
57
- A *module-import-declaration* imports both the named translation unit(s)
58
- and any modules named by exported *module-import-declaration*s within
59
- them, recursively.
60
-
61
- [*Example 2*:
62
-
63
- Translation unit #1
64
-
65
- ``` cpp
66
- export module Q;
67
- export int sq(int i) { return i*i; }
68
- ```
69
-
70
- Translation unit #2
71
-
72
- ``` cpp
73
- export module R;
74
- export import Q;
75
- ```
76
-
77
- Translation unit #3
78
-
79
- ``` cpp
80
- import R;
81
- int main() { return sq(9); } // OK: sq from module Q
82
- ```
83
-
84
- — *end example*]
85
-
86
- — *end note*]
87
-
88
- A namespace member can also be referred to after the `::` scope
89
- resolution operator [[expr.prim.id.qual]] applied to the name of its
90
- namespace or the name of a namespace which nominates the member’s
91
- namespace in a *using-directive*; see  [[namespace.qual]].
92
-
93
- The outermost declarative region of a translation unit is also a
94
- namespace, called the *global namespace*. A name declared in the global
95
- namespace has *global namespace scope* (also called *global scope*). The
96
- potential scope of such a name begins at its point of declaration
97
- [[basic.scope.pdecl]] and ends at the end of the translation unit that
98
- is its declarative region. A name with global namespace scope is said to
99
- be a *global name*.
100
-
 
1
  ### Namespace scope <a id="basic.scope.namespace">[[basic.scope.namespace]]</a>
2
 
3
+ Any *namespace-definition* for a namespace N introduces a
4
+ *namespace scope* that includes the *namespace-body* for every
5
+ *namespace-definition* for N. For each non-friend redeclaration or
6
+ specialization whose target scope is or is contained by the scope, the
7
+ portion after the *declarator-id*, *class-head-name*, or
8
+ *enum-head-name* is also included in the scope. The global scope is the
9
+ namespace scope of the global namespace [[basic.namespace]].
 
 
 
 
10
 
11
  [*Example 1*:
12
 
13
  ``` cpp
14
+ namespace Q {
15
+ namespace V { void f(); }
16
+ void V::f() { // in the scope of V
17
+ void h(); // declares Q::V::h
 
18
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  }
20
  ```
21
 
22
  — *end example*]
23