From Jason Turner

[basic.scope.scope]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmp4g83swdz/{from.md → to.md} +195 -0
tmp/tmp4g83swdz/{from.md → to.md} RENAMED
@@ -0,0 +1,195 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ### General <a id="basic.scope.scope">[[basic.scope.scope]]</a>
2
+
3
+ The declarations in a program appear in a number of *scopes* that are in
4
+ general discontiguous. The *global scope* contains the entire program;
5
+ every other scope S is introduced by a declaration,
6
+ *parameter-declaration-clause*, *statement*, or *handler* (as described
7
+ in the following subclauses of [[basic.scope]]) appearing in another
8
+ scope which thereby contains S. An *enclosing scope* at a program point
9
+ is any scope that contains it; the smallest such scope is said to be the
10
+ *immediate scope* at that point. A scope *intervenes* between a program
11
+ point P and a scope S (that does not contain P) if it is or contains S
12
+ but does not contain P.
13
+
14
+ Unless otherwise specified:
15
+
16
+ - The smallest scope that contains a scope S is the *parent scope* of S.
17
+ - No two declarations (re)introduce the same entity.
18
+ - A declaration *inhabits* the immediate scope at its locus
19
+ [[basic.scope.pdecl]].
20
+ - A declaration’s *target scope* is the scope it inhabits.
21
+ - Any names (re)introduced by a declaration are *bound* to it in its
22
+ target scope.
23
+
24
+ An entity *belongs* to a scope S if S is the target scope of a
25
+ declaration of the entity.
26
+
27
+ [*Note 1*:
28
+
29
+ Special cases include that:
30
+
31
+ - Template parameter scopes are parents only to other template parameter
32
+ scopes [[basic.scope.temp]].
33
+ - Corresponding declarations with appropriate linkage declare the same
34
+ entity [[basic.link]].
35
+ - The declaration in a *template-declaration* inhabits the same scope as
36
+ the *template-declaration*.
37
+ - Friend declarations and declarations of qualified names and template
38
+ specializations do not bind names [[dcl.meaning]]; those with
39
+ qualified names target a specified scope, and other friend
40
+ declarations and certain *elaborated-type-specifier*s
41
+ [[dcl.type.elab]] target a larger enclosing scope.
42
+ - Block-scope extern declarations target a larger enclosing scope but
43
+ bind a name in their immediate scope.
44
+ - The names of unscoped enumerators are bound in the two innermost
45
+ enclosing scopes [[dcl.enum]].
46
+ - A class’s name is also bound in its own scope [[class.pre]].
47
+ - The names of the members of an anonymous union are bound in the
48
+ union’s parent scope [[class.union.anon]].
49
+
50
+ — *end note*]
51
+
52
+ Two non-static member functions have *corresponding object parameters*
53
+ if:
54
+
55
+ - exactly one is an implicit object member function with no
56
+ *ref-qualifier* and the types of their object parameters [[dcl.fct]],
57
+ after removing top-level references, are the same, or
58
+ - their object parameters have the same type.
59
+
60
+ Two non-static member function templates have *corresponding object
61
+ parameters* if:
62
+
63
+ - exactly one is an implicit object member function with no
64
+ *ref-qualifier* and the types of their object parameters, after
65
+ removing any references, are equivalent, or
66
+ - the types of their object parameters are equivalent.
67
+
68
+ Two function templates have *corresponding signatures* if their
69
+ *template-parameter-list*s have the same length, their corresponding
70
+ *template-parameter*s are equivalent, they have equivalent
71
+ non-object-parameter-type-lists and return types (if any), and, if both
72
+ are non-static members, they have corresponding object parameters.
73
+
74
+ Two declarations *correspond* if they (re)introduce the same name, both
75
+ declare constructors, or both declare destructors, unless
76
+
77
+ - either is a *using-declarator*, or
78
+ - one declares a type (not a *typedef-name*) and the other declares a
79
+ variable, non-static data member other than of an anonymous union
80
+ [[class.union.anon]], enumerator, function, or function template, or
81
+ - each declares a function or function template, except when
82
+ - both declare functions with the same
83
+ non-object-parameter-type-list,[^3] equivalent [[temp.over.link]]
84
+ trailing *requires-clause*s (if any, except as specified in
85
+ [[temp.friend]]), and, if both are non-static members, they have
86
+ corresponding object parameters, or
87
+ - both declare function templates with corresponding signatures and
88
+ equivalent *template-head*s and trailing *requires-clause*s (if
89
+ any).
90
+
91
+ [*Note 2*:
92
+
93
+ Declarations can correspond even if neither binds a name.
94
+
95
+ [*Example 1*:
96
+
97
+ ``` cpp
98
+ struct A {
99
+ friend void f(); // #1
100
+ };
101
+ struct B {
102
+ friend void f() {} // corresponds to, and defines, #1
103
+ };
104
+ ```
105
+
106
+ — *end example*]
107
+
108
+ — *end note*]
109
+
110
+ [*Example 2*:
111
+
112
+ ``` cpp
113
+ typedef int Int;
114
+ enum E : int { a };
115
+ void f(int); // #1
116
+ void f(Int) {} // defines #1
117
+ void f(E) {} // OK, another overload
118
+
119
+ struct X {
120
+ static void f();
121
+ void f() const; // error: redeclaration
122
+ void g();
123
+ void g() const; // OK
124
+ void g() &; // error: redeclaration
125
+
126
+ void h(this X&, int);
127
+ void h(int) &&; // OK, another overload
128
+ void j(this const X&);
129
+ void j() const &; // error: redeclaration
130
+ void k();
131
+ void k(this X&); // error: redeclaration
132
+ };
133
+ ```
134
+
135
+ — *end example*]
136
+
137
+ Two declarations *potentially conflict* if they correspond and cause
138
+ their shared name to denote different entities [[basic.link]]. The
139
+ program is ill-formed if, in any scope, a name is bound to two
140
+ declarations that potentially conflict and one precedes the other
141
+ [[basic.lookup]].
142
+
143
+ [*Note 3*: Overload resolution can consider potentially conflicting
144
+ declarations found in multiple scopes (e.g., via *using-directive*s or
145
+ for operator functions), in which case it is often
146
+ ambiguous. — *end note*]
147
+
148
+ [*Example 3*:
149
+
150
+ ``` cpp
151
+ void f() {
152
+ int x,y;
153
+ void x(); // error: different entity for x
154
+ int y; // error: redefinition
155
+ }
156
+ enum { f }; // error: different entity for ::f
157
+ namespace A {}
158
+ namespace B = A;
159
+ namespace B = A; // OK, no effect
160
+ namespace B = B; // OK, no effect
161
+ namespace A = B; // OK, no effect
162
+ namespace B {} // error: different entity for B
163
+ ```
164
+
165
+ — *end example*]
166
+
167
+ A declaration is *nominable* in a class, class template, or namespace E
168
+ at a point P if it precedes P, it does not inhabit a block scope, and
169
+ its target scope is the scope associated with E or, if E is a namespace,
170
+ any element of the inline namespace set of E [[namespace.def]].
171
+
172
+ [*Example 4*:
173
+
174
+ ``` cpp
175
+ namespace A {
176
+ void f() {void g();}
177
+ inline namespace B {
178
+ struct S {
179
+ friend void h();
180
+ static int i;
181
+ };
182
+ }
183
+ }
184
+ ```
185
+
186
+ At the end of this example, the declarations of `f`, `B`, `S`, and `h`
187
+ are nominable in `A`, but those of `g` and `i` are not.
188
+
189
+ — *end example*]
190
+
191
+ When instantiating a templated entity [[temp.pre]], any scope S
192
+ introduced by any part of the template definition is considered to be
193
+ introduced by the instantiated entity and to contain the instantiations
194
+ of any declarations that inhabit S.
195
+